line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ex::constant::vars; |
2
|
|
|
|
|
|
|
$ex::constant::vars::VERSION = '0.06'; |
3
|
4
|
|
|
4
|
|
70021
|
use 5.006; |
|
4
|
|
|
|
|
14
|
|
4
|
4
|
|
|
4
|
|
20
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
101
|
|
5
|
4
|
|
|
4
|
|
19
|
use warnings; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
120
|
|
6
|
4
|
|
|
4
|
|
27
|
use Carp; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
1842
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Exporter; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = qw( |
11
|
|
|
|
|
|
|
Exporter |
12
|
|
|
|
|
|
|
ex::constant::vars::scalar |
13
|
|
|
|
|
|
|
ex::constant::vars::array |
14
|
|
|
|
|
|
|
ex::constant::vars::hash |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
our @EXPORT_OK = qw( const SCALAR ARRAY HASH ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub const { |
19
|
14
|
|
|
14
|
1
|
25
|
my $type = shift; |
20
|
14
|
|
|
|
|
38
|
my @values = splice @_, 1; |
21
|
14
|
100
|
|
|
|
43
|
if ( $type eq 'scalar' ) { |
|
|
100
|
|
|
|
|
|
22
|
4
|
|
|
|
|
7
|
return tie ${$_[0]}, __PACKAGE__ . '::' . $type, @values; |
|
4
|
|
|
|
|
40
|
|
23
|
|
|
|
|
|
|
} elsif ( $type eq 'array' ) { |
24
|
5
|
|
|
|
|
8
|
return tie @{$_[0]}, __PACKAGE__ . '::' . $type, @values; |
|
5
|
|
|
|
|
32
|
|
25
|
|
|
|
|
|
|
} else { |
26
|
5
|
|
|
|
|
7
|
return tie %{$_[0]}, __PACKAGE__ . '::' . $type, @values; |
|
5
|
|
|
|
|
26
|
|
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
4
|
|
|
4
|
|
22
|
sub SCALAR (\$$) { 'scalar', @_ } |
31
|
5
|
|
|
5
|
0
|
146
|
sub ARRAY (\@@) { 'array', @_ } |
32
|
5
|
|
|
5
|
0
|
21
|
sub HASH (\%%) { 'hash', @_ } |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub import { |
35
|
6
|
|
|
6
|
|
48
|
my $self = shift; |
36
|
6
|
100
|
|
|
|
2313
|
return unless @_; |
37
|
4
|
100
|
66
|
|
|
28
|
if ( @_ == 1 && $_[0] eq 'const' ) { |
38
|
2
|
|
|
|
|
2978
|
$self->export_to_level( 1, $self, @EXPORT_OK ); |
39
|
|
|
|
|
|
|
} else { |
40
|
2
|
|
|
|
|
11
|
my %variables = @_; |
41
|
2
|
|
|
|
|
5
|
my $caller = caller( 0 ); |
42
|
2
|
|
|
|
|
14
|
while ( my( $var, $val ) = each %variables ) { |
43
|
7
|
|
|
|
|
21
|
my( $prefix, $name ) = split //, $var, 2; |
44
|
7
|
50
|
|
|
|
32
|
croak "'$var' not a valid variable name" unless $prefix =~ /^[\$\@\%]$/; |
45
|
7
|
100
|
|
|
|
24
|
if ( $prefix eq '$' ) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
46
|
4
|
|
|
4
|
|
21
|
no strict 'refs'; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
518
|
|
47
|
2
|
|
|
|
|
2
|
*{__PACKAGE__ . "::variables::$name"} = \$val; |
|
2
|
|
|
|
|
12
|
|
48
|
2
|
|
|
|
|
2
|
*{"${caller}::$name"} = \${__PACKAGE__ . "::variables::$name"}; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
7
|
|
49
|
2
|
|
|
|
|
3
|
const SCALAR ${"${caller}::$name"}, $val; |
|
2
|
|
|
|
|
6
|
|
50
|
|
|
|
|
|
|
} elsif ( $prefix eq '@' ) { |
51
|
4
|
|
|
4
|
|
21
|
no strict 'refs'; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
485
|
|
52
|
2
|
|
|
|
|
3
|
*{__PACKAGE__ . "::variables::$name"} = \@{$val}; |
|
2
|
|
|
|
|
16
|
|
|
2
|
|
|
|
|
2
|
|
53
|
2
|
|
|
|
|
4
|
*{"${caller}::$name"} = \@{__PACKAGE__ . "::variables::$name"}; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
6
|
|
54
|
2
|
|
|
|
|
4
|
const ARRAY @{"${caller}::$name"}, @{$val}; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
5
|
|
55
|
|
|
|
|
|
|
} elsif ( $prefix eq '%' ) { |
56
|
4
|
|
|
4
|
|
19
|
no strict 'refs'; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
647
|
|
57
|
3
|
|
|
|
|
4
|
*{__PACKAGE__ . "::variables::$name"} = \%{$val}; |
|
3
|
|
|
|
|
18
|
|
|
3
|
|
|
|
|
6
|
|
58
|
3
|
|
|
|
|
6
|
*{"${caller}::$name"} = \%{__PACKAGE__ . "::variables::$name"}; |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
10
|
|
59
|
3
|
|
|
|
|
5
|
const HASH %{"${caller}::$name"}, %{$val}; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
21
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
package ex::constant::vars::scalar; |
67
|
|
|
|
|
|
|
$ex::constant::vars::scalar::VERSION = '0.06'; |
68
|
4
|
|
|
4
|
|
19
|
use Carp; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
719
|
|
69
|
|
|
|
|
|
|
$Carp::CarpLevel = 1; |
70
|
7
|
|
|
7
|
|
137
|
sub TIESCALAR { shift; bless \(my $scalar = shift), __PACKAGE__ } |
|
7
|
|
|
|
|
2232
|
|
71
|
15
|
|
|
15
|
|
2257
|
sub FETCH { ${$_[0]} } |
|
15
|
|
|
|
|
78
|
|
72
|
8
|
|
|
8
|
|
1443
|
sub STORE { croak "Modification of a read-only value attempted" } |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
package ex::constant::vars::array; |
76
|
|
|
|
|
|
|
$ex::constant::vars::array::VERSION = '0.06'; |
77
|
4
|
|
|
4
|
|
19
|
use Carp; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
986
|
|
78
|
|
|
|
|
|
|
$Carp::CarpLevel = 1; |
79
|
7
|
|
|
7
|
|
13
|
sub TIEARRAY { shift; bless $_=\@_, __PACKAGE__ } |
|
7
|
|
|
|
|
48
|
|
80
|
38
|
|
|
38
|
|
357
|
sub FETCH { $_[0]->[$_[1]] } |
81
|
15
|
|
|
15
|
|
2937
|
sub FETCHSIZE { @{$_[0]} } |
|
15
|
|
|
|
|
51
|
|
82
|
1
|
|
|
1
|
|
108
|
sub EXISTS { exists $_[0]->[$_[1]] } |
83
|
13
|
|
|
13
|
|
2011
|
sub STORE { croak "Modification of a read-only value attempted" } |
84
|
|
|
|
|
|
|
*CLEAR = *EXTEND = *POP = *PUSH = *SHIFT = |
85
|
|
|
|
|
|
|
*UNSHIFT = *SPLICE = *STORESIZE = *DELETE = \*STORE; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
package ex::constant::vars::hash; |
89
|
|
|
|
|
|
|
$ex::constant::vars::hash::VERSION = '0.06'; |
90
|
4
|
|
|
4
|
|
46
|
use Carp; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
955
|
|
91
|
|
|
|
|
|
|
$Carp::CarpLevel = 1; |
92
|
7
|
|
|
7
|
|
1849
|
sub TIEHASH { bless {@_[1...$#_]}, __PACKAGE__ } |
93
|
56
|
|
|
56
|
|
382
|
sub FETCH { $_[0]->{$_[1]} } |
94
|
19
|
|
|
19
|
|
4033
|
sub FIRSTKEY { keys %{$_[0]}; each %{$_[0]} } |
|
19
|
|
|
|
|
55
|
|
|
19
|
|
|
|
|
32
|
|
|
19
|
|
|
|
|
72
|
|
95
|
56
|
|
|
56
|
|
61
|
sub NEXTKEY { each %{$_[0]} } |
|
56
|
|
|
|
|
154
|
|
96
|
1
|
|
|
1
|
|
9
|
sub EXISTS { exists $_[0]->{$_[1]} } |
97
|
15
|
|
|
15
|
|
2270
|
sub STORE { croak "Modification of a read-only value attempted" } |
98
|
|
|
|
|
|
|
*CLEAR = *DELETE = \*STORE; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__END__ |