line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sub::Args; |
2
|
3
|
|
|
3
|
|
1773
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
110
|
|
3
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
81
|
|
4
|
3
|
|
|
3
|
|
71
|
use 5.008001; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
109
|
|
5
|
3
|
|
|
3
|
|
15
|
use Exporter 'import'; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
171
|
|
6
|
|
|
|
|
|
|
our @EXPORT = qw( args args_pos ); |
7
|
3
|
|
|
3
|
|
15
|
use Carp (); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
1556
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.08'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub args { |
12
|
21
|
|
|
21
|
1
|
8257
|
my $rule = shift; |
13
|
|
|
|
|
|
|
|
14
|
21
|
100
|
|
|
|
95
|
if (ref $rule ne 'HASH') { |
15
|
2
|
|
|
|
|
381
|
Carp::croak "args method require hashref's rule."; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
19
|
|
|
|
|
38
|
my $invocant = caller(0); |
19
|
|
|
|
|
|
|
|
20
|
19
|
100
|
|
|
|
52
|
my $caller_args = ref($_[0]) eq 'HASH' ? $_[0] : {@_}; |
21
|
19
|
100
|
|
|
|
59
|
unless (keys %$caller_args) { |
22
|
|
|
|
|
|
|
package DB; |
23
|
16
|
|
|
|
|
112
|
() = caller(1); |
24
|
|
|
|
|
|
|
|
25
|
16
|
100
|
66
|
|
|
83
|
shift @DB::args if $invocant eq (ref($DB::args[0])||$DB::args[0]); |
26
|
|
|
|
|
|
|
|
27
|
16
|
100
|
|
|
|
35
|
if (ref($DB::args[0]) eq 'HASH') { |
28
|
10
|
|
|
|
|
21
|
$caller_args = $DB::args[0]; |
29
|
|
|
|
|
|
|
} else { |
30
|
6
|
100
|
|
|
|
22
|
if (scalar(@DB::args) % 2 == 1 ) { |
31
|
1
|
|
|
|
|
133
|
Carp::confess "arguments not allow excluding hash or hashref"; |
32
|
|
|
|
|
|
|
} |
33
|
5
|
|
|
|
|
18
|
$caller_args = {@DB::args}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
18
|
100
|
100
|
|
|
53
|
map {($rule->{$_} && not defined $caller_args->{$_}) ? Carp::confess "Mandatory parameter '$_' missing.": () } keys %$rule; |
|
34
|
|
|
|
|
446
|
|
38
|
|
|
|
|
|
|
|
39
|
16
|
100
|
|
|
|
36
|
map {(not defined $rule->{$_}) ? Carp::confess "not listed in the following parameter: $_.": () } keys %$caller_args; |
|
22
|
|
|
|
|
509
|
|
40
|
|
|
|
|
|
|
|
41
|
14
|
100
|
|
|
|
21
|
map {$caller_args->{$_} = undef unless exists $caller_args->{$_}} keys %$rule; |
|
28
|
|
|
|
|
103
|
|
42
|
|
|
|
|
|
|
|
43
|
14
|
|
|
|
|
38
|
Internals::SvREADONLY %$caller_args, 1; |
44
|
14
|
|
|
|
|
31
|
$caller_args; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub args_pos { |
48
|
6
|
|
|
6
|
1
|
2141
|
my $invocant = caller(0); |
49
|
|
|
|
|
|
|
{ |
50
|
6
|
|
|
|
|
8
|
package DB; |
51
|
6
|
|
|
|
|
36
|
() = caller(1); |
52
|
6
|
50
|
66
|
|
|
37
|
shift @DB::args if $invocant eq (ref($DB::args[0])||$DB::args[0]); |
53
|
|
|
|
|
|
|
} |
54
|
6
|
|
|
|
|
11
|
my @args = @DB::args; |
55
|
|
|
|
|
|
|
|
56
|
6
|
|
|
|
|
7
|
my @expected; |
57
|
6
|
|
|
|
|
17
|
for(my $i = 0; $i < @_; $i++){ |
58
|
17
|
100
|
100
|
|
|
57
|
if ($_[$i] && not defined $args[0]) { |
59
|
1
|
|
|
|
|
287
|
Carp::confess "missing mandatory parameter. pos: $i"; |
60
|
|
|
|
|
|
|
} |
61
|
16
|
|
|
|
|
42
|
$expected[$i] = shift @args; |
62
|
|
|
|
|
|
|
} |
63
|
5
|
100
|
|
|
|
9
|
if (scalar(@args) > 0) { |
64
|
1
|
|
|
|
|
341
|
Carp::confess 'too much arguments. This function requires only ' . scalar(@_) . ' arguments.'; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
4
|
50
|
|
|
|
35
|
wantarray ? @expected : \@expected; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
71
|
|
|
|
|
|
|
__END__ |