line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Devel::TakeHashArgs; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
41008
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
386
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.006'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Exporter; |
9
|
|
|
|
|
|
|
our @ISA = 'Exporter'; |
10
|
|
|
|
|
|
|
our @EXPORT = qw(get_args_as_hash); |
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw(set_self_args_as_hash); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub set_self_args_as_hash { |
14
|
0
|
|
|
0
|
1
|
0
|
my ( $in_args, $opts, $mandatory_opts, $valid_opts ) = @_; |
15
|
0
|
|
|
|
|
0
|
my $class = shift @$in_args; |
16
|
|
|
|
|
|
|
|
17
|
0
|
0
|
|
|
|
0
|
get_args_as_hash( |
18
|
|
|
|
|
|
|
$in_args, \ my %args, $opts, $mandatory_opts, $valid_opts |
19
|
|
|
|
|
|
|
) or return 0; # $@ will be set with an error; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
0
|
my $self = bless {}, $class; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
0
|
$self->$_( $args{ $_ } ) for keys %args; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
0
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub get_args_as_hash { |
29
|
9
|
|
|
9
|
1
|
4430
|
my ( $in_args, $out_args, $opts, $mandatory_opts, $valid_opts ) = @_; |
30
|
|
|
|
|
|
|
|
31
|
9
|
100
|
|
|
|
28
|
$valid_opts = [] |
32
|
|
|
|
|
|
|
unless defined $valid_opts; |
33
|
|
|
|
|
|
|
|
34
|
9
|
100
|
100
|
|
|
36
|
@$in_args & 1 |
35
|
|
|
|
|
|
|
and $@ = "Must have correct number of arguments" |
36
|
|
|
|
|
|
|
and return 0; |
37
|
|
|
|
|
|
|
|
38
|
8
|
|
|
|
|
24
|
%$out_args = @$in_args; |
39
|
8
|
|
|
|
|
40
|
$out_args->{ +lc } = delete $out_args->{ $_ } for keys %$out_args; |
40
|
|
|
|
|
|
|
|
41
|
8
|
100
|
|
|
|
41
|
%$out_args = ( |
42
|
8
|
|
|
|
|
14
|
%{ $opts || {} }, |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
%$out_args, |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
8
|
|
|
|
|
19
|
for ( @$mandatory_opts ) { |
48
|
2
|
100
|
|
|
|
9
|
unless ( exists $out_args->{$_} ) { |
49
|
1
|
|
|
|
|
4
|
$@ = "Missing mandatory argument `$_`"; |
50
|
1
|
|
|
|
|
6
|
return 0; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
7
|
100
|
|
|
|
15
|
if ( @$valid_opts ) { |
55
|
2
|
|
|
|
|
3
|
my %valid; |
56
|
2
|
|
|
|
|
7
|
@valid{ @$valid_opts } = (1) x @$valid_opts; |
57
|
2
|
|
|
|
|
6
|
for ( keys %$out_args ) { |
58
|
2
|
100
|
|
|
|
7
|
unless ( $valid{$_} ) { |
59
|
1
|
|
|
|
|
4
|
$@ = "Invalid argument `$_`"; |
60
|
1
|
|
|
|
|
6
|
return 0; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
6
|
|
|
|
|
20
|
1; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
__END__ |