OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [Integration_test/] [synthetic_sim/] [perl_lib/] [constant/] [boolean.pm] - Blame information for rev 56

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 56 alirezamon
#!/usr/bin/perl -c
2
 
3
package constant::boolean;
4
 
5
=head1 NAME
6
 
7
constant::boolean - Define TRUE and FALSE constants.
8
 
9
=head1 SYNOPSIS
10
 
11
  use constant::boolean;
12
 
13
  use File::Spec;
14
 
15
  sub is_package_exist {
16
    my ($package) = @_;
17
    return FALSE unless defined $package;
18
    foreach my $inc (@INC) {
19
        my $filename = File::Spec->catfile(
20
            split( /\//, $inc ), split( /\::/, $package )
21
        ) . '.pm';
22
        return TRUE if -f $filename;
23
    };
24
    return FALSE;
25
  };
26
 
27
  no constant::boolean;
28
 
29
=head1 DESCRIPTION
30
 
31
Defines C<TRUE> and C<FALSE> constants in caller's namespace.  You could use
32
simple values like empty string or zero for false, or any non-empty and
33
non-zero string value as true, but the C<TRUE> and C<FALSE> constants are more
34
descriptive.
35
 
36
It is virtually the same as:
37
 
38
  # double "not" operator is used for converting scalar to boolean value
39
  use constant TRUE => !! 1;
40
  use constant FALSE => !! '';
41
 
42
The constants exported by C<constant::boolean> are not reported by
43
L<Test::Pod::Coverage>, so it is more convenient to use this module than to
44
define C<TRUE> and C<FALSE> constants by yourself.
45
 
46
The constants can be removed from class API with C<no constant::boolean>
47
pragma or some universal tool like L<namespace::clean>.
48
 
49
=for readme stop
50
 
51
=cut
52
 
53
use 5.006;
54
 
55
use strict;
56
use warnings;
57
 
58
our $VERSION = '0.02';
59
 
60
 
61
sub import {
62
    my $caller = caller;
63
 
64
    no strict 'refs';
65
    # double "not" operator is used for converting scalar to boolean value
66
    *{"${caller}::TRUE"}  = sub () { !! 1 };
67
    *{"${caller}::FALSE"} = sub () { !! '' };
68
 
69
    return 1;
70
};
71
 
72
 
73
sub unimport {
74
    require Symbol::Util;
75
 
76
    my $caller = caller;
77
    Symbol::Util::delete_sub("${caller}::$_") foreach qw( TRUE FALSE );
78
 
79
    return 1;
80
};
81
 
82
 
83
1;
84
 
85
 
86
=head1 BUGS
87
 
88
If you find the bug or want to implement new features, please report it at
89
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=constant-boolean>
90
 
91
=for readme continue
92
 
93
=head1 AUTHOR
94
 
95
Piotr Roszatycki <dexter@cpan.org>
96
 
97
=head1 LICENSE
98
 
99
Copyright 2008, 2009 by Piotr Roszatycki <dexter@cpan.org>.
100
 
101
This program is free software; you can redistribute it and/or modify it
102
under the same terms as Perl itself.
103
 
104
See L<http://www.perl.com/perl/misc/Artistic.html>

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.