line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::Accessor::Array; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2016-03-28'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.02'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub import { |
7
|
2
|
|
|
2
|
|
283
|
my ($class0, $spec) = @_; |
8
|
2
|
|
|
|
|
3
|
my $caller = caller(); |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
15120
|
no warnings 'redefine'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
155
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# generate accessors |
13
|
2
|
|
|
|
|
2
|
for my $meth (keys %{$spec->{accessors}}) { |
|
2
|
|
|
|
|
6
|
|
14
|
4
|
|
|
|
|
4
|
my $idx = $spec->{accessors}{$meth}; |
15
|
4
|
|
|
|
|
4
|
my $code_str = 'sub (;$) { '; |
16
|
4
|
|
|
|
|
6
|
$code_str .= "\$_[0][$idx] = \$_[1] if \@_ > 1; "; |
17
|
4
|
|
|
|
|
3
|
$code_str .= "\$_[0][$idx]; "; |
18
|
4
|
|
|
|
|
3
|
$code_str .= "}"; |
19
|
|
|
|
|
|
|
#say "D:accessor code for $meth: ", $code_str; |
20
|
4
|
50
|
|
1
|
|
253
|
*{"$caller\::$meth"} = eval $code_str; |
|
4
|
50
|
|
|
|
16
|
|
|
1
|
50
|
|
|
|
20
|
|
|
1
|
50
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
|
1
|
|
|
|
|
1
|
|
21
|
4
|
50
|
|
|
|
10
|
die if $@; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# generate constructor |
25
|
|
|
|
|
|
|
{ |
26
|
2
|
|
|
|
|
2
|
my $code_str = 'sub { my $class = shift; bless [], $class }'; |
|
2
|
|
|
|
|
2
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#say "D:constructor code for class $caller: ", $code_str; |
29
|
2
|
|
100
|
|
|
7
|
my $constructor = $spec->{constructor} || "new"; |
30
|
2
|
50
|
|
|
|
1
|
unless (*{"$caller\::$constructor"}{CODE}) { |
|
2
|
|
|
|
|
9
|
|
31
|
2
|
|
|
1
|
|
101
|
*{"$caller\::$constructor"} = eval $code_str; |
|
2
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
1750
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
44
|
|
|
1
|
|
|
|
|
4
|
|
32
|
2
|
50
|
|
|
|
38
|
die if $@; |
33
|
|
|
|
|
|
|
}; |
34
|
|
|
|
|
|
|
}; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
1; |
38
|
|
|
|
|
|
|
# ABSTRACT: Generate accessors/constructor for array-based object |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
__END__ |