line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::AutoClass::Args; |
2
|
13
|
|
|
13
|
|
2676
|
use strict; |
|
13
|
|
|
|
|
114
|
|
|
13
|
|
|
|
|
430
|
|
3
|
13
|
|
|
13
|
|
61
|
use Carp; |
|
13
|
|
|
|
|
19
|
|
|
13
|
|
|
|
|
17015
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
sub new { |
6
|
183
|
|
|
183
|
0
|
6803
|
my($class,@args)=@_; |
7
|
183
|
|
33
|
|
|
758
|
$class=(ref $class)||$class; |
8
|
183
|
|
|
|
|
507
|
my $self=bless _fix_args(@args), $class; |
9
|
|
|
|
|
|
|
} |
10
|
|
|
|
|
|
|
sub get_args { |
11
|
2
|
|
|
2
|
0
|
13
|
my($self,@args)=@_; |
12
|
2
|
50
|
33
|
|
|
11
|
@args=@{$args[0]} if @args==1 && 'ARRAY' eq ref $args[0]; |
|
0
|
|
|
|
|
0
|
|
13
|
2
|
|
|
|
|
8
|
@args=fix_keyword(@args); |
14
|
2
|
|
|
|
|
7
|
my @results=map {$self->{$_}} @args; |
|
6
|
|
|
|
|
16
|
|
15
|
2
|
50
|
|
|
|
16
|
wantarray? @results: $results[0]; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
sub getall_args { |
18
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
19
|
0
|
0
|
|
|
|
0
|
wantarray? %$self: {%$self}; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
sub set_args { |
22
|
1
|
|
|
1
|
0
|
2815
|
my($self,@args)=@_; |
23
|
1
|
|
|
|
|
5
|
my $args=_fix_args(@args); |
24
|
1
|
|
|
|
|
7
|
while(my($key,$value)=each %$args) { |
25
|
3
|
|
|
|
|
3310
|
$self->$key($value); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
sub fix_keyword { |
29
|
563
|
|
|
563
|
0
|
1162
|
my @keywords=@_; # copies input, so update-in-place doesn't munge it |
30
|
563
|
|
|
|
|
1135
|
for my $keyword (@keywords) { |
31
|
998
|
50
|
|
|
|
2122
|
next unless defined $keyword; |
32
|
998
|
50
|
|
|
|
7793
|
$keyword=~s/^-*(.*)$/\L$1/ unless ref $keyword; # updates in place |
33
|
|
|
|
|
|
|
} |
34
|
563
|
100
|
|
|
|
2685
|
wantarray? @keywords: $keywords[0]; |
35
|
|
|
|
|
|
|
} |
36
|
41
|
|
|
41
|
0
|
1440
|
sub fix_keywords {fix_keyword(@_);} |
37
|
0
|
0
|
|
0
|
0
|
0
|
sub is_keyword {!(@_%2) && $_[0]=~/^-/;} |
38
|
0
|
0
|
|
0
|
0
|
0
|
sub is_positional {@_%2 || $_[0]!~/^-/;} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _fix_args { |
41
|
13
|
|
|
13
|
|
88
|
no warnings; |
|
13
|
|
|
|
|
26
|
|
|
13
|
|
|
|
|
3391
|
|
42
|
184
|
|
|
184
|
|
424
|
my(@args)=@_; |
43
|
184
|
100
|
100
|
|
|
941
|
@args=@{$args[0]} if @args==1 && 'ARRAY' eq ref $args[0]; |
|
1
|
|
|
|
|
5
|
|
44
|
184
|
100
|
66
|
|
|
765
|
@args=%{$args[0]} if @args==1 && 'HASH' eq ref $args[0]; |
|
3
|
|
|
|
|
14
|
|
45
|
184
|
50
|
33
|
|
|
534
|
@args=%{$args[0]} if @args==1 && $args[0]=~/HASH/; # treat object like HASH |
|
0
|
|
|
|
|
0
|
|
46
|
184
|
50
|
|
|
|
512
|
confess("Malformed keyword argument list (odd number of elements): @args") if @args%2; |
47
|
184
|
|
|
|
|
352
|
my $args={}; |
48
|
184
|
|
|
|
|
323
|
my %counts; |
49
|
184
|
|
|
|
|
494
|
while(@args) { |
50
|
239
|
|
|
|
|
533
|
my($keyword,$value)=(fix_keyword(shift @args),shift @args); |
51
|
239
|
100
|
|
|
|
1247
|
$args->{$keyword}=$value if $counts{$keyword}==0; |
52
|
239
|
100
|
|
|
|
546
|
$args->{$keyword}=[$args->{$keyword},$value] if $counts{$keyword}==1; |
53
|
239
|
100
|
|
|
|
522
|
push(@{$args->{$keyword}},$value) if $counts{$keyword}>1; |
|
2
|
|
|
|
|
6
|
|
54
|
239
|
|
|
|
|
680
|
$counts{$keyword}++; |
55
|
|
|
|
|
|
|
} |
56
|
184
|
|
|
|
|
1047
|
$args; |
57
|
|
|
|
|
|
|
} |
58
|
13
|
|
|
13
|
|
106
|
use vars qw($AUTOLOAD); |
|
13
|
|
|
|
|
23
|
|
|
13
|
|
|
|
|
2556
|
|
59
|
|
|
|
|
|
|
sub AUTOLOAD { |
60
|
80
|
|
|
80
|
|
367
|
my $self=shift; |
61
|
80
|
|
|
|
|
684
|
$AUTOLOAD=~s/^.*:://; # strip class qualification |
62
|
80
|
50
|
|
|
|
246
|
return if $AUTOLOAD eq 'DESTROY'; # the books say you should do this |
63
|
80
|
|
|
|
|
290
|
my $keyword=fix_keyword($AUTOLOAD); |
64
|
80
|
100
|
100
|
|
|
661
|
return if @_==0 && !exists $self->{$keyword}; |
65
|
13
|
|
|
|
|
15
|
my $result; |
66
|
13
|
100
|
|
|
|
77
|
return $self->{$keyword} if @_==0; |
67
|
3
|
50
|
|
|
|
32
|
return $self->{$keyword}=$_[0] if @_==1; |
68
|
0
|
0
|
|
|
|
|
return $self->{$keyword}=[@_] if @_>1; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |