line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/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 and C 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 and C 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 are not reported by |
43
|
|
|
|
|
|
|
L, so it is more convenient to use this module than to |
44
|
|
|
|
|
|
|
define C and C constants by yourself. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
The constants can be removed from class API with C |
47
|
|
|
|
|
|
|
pragma or some universal tool like L. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=for readme stop |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
2
|
|
|
2
|
|
1591
|
use 5.006; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
93
|
|
54
|
|
|
|
|
|
|
|
55
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
73
|
|
56
|
2
|
|
|
2
|
|
24
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
154
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub import { |
62
|
2
|
|
|
2
|
|
17
|
my $caller = caller; |
63
|
|
|
|
|
|
|
|
64
|
2
|
|
|
2
|
|
10
|
no strict 'refs'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
384
|
|
65
|
|
|
|
|
|
|
# double "not" operator is used for converting scalar to boolean value |
66
|
2
|
|
|
|
|
4
|
*{"${caller}::TRUE"} = sub () { !! 1 }; |
|
2
|
|
|
|
|
14
|
|
67
|
2
|
|
|
|
|
478
|
*{"${caller}::FALSE"} = sub () { !! '' }; |
|
2
|
|
|
|
|
12
|
|
68
|
|
|
|
|
|
|
|
69
|
2
|
|
|
|
|
43
|
return 1; |
70
|
|
|
|
|
|
|
}; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub unimport { |
74
|
1
|
|
|
1
|
|
3358
|
require Symbol::Util; |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
|
|
2485
|
my $caller = caller; |
77
|
1
|
|
|
|
|
7
|
Symbol::Util::delete_sub("${caller}::$_") foreach qw( TRUE FALSE ); |
78
|
|
|
|
|
|
|
|
79
|
1
|
|
|
|
|
173
|
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 |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=for readme continue |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 AUTHOR |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Piotr Roszatycki |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 LICENSE |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Copyright 2008, 2009 by Piotr Roszatycki . |
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 |