line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Var::Extract; |
2
|
1
|
|
|
1
|
|
46575
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
4
|
1
|
|
|
1
|
|
17625
|
use PadWalker qw(var_name); |
|
1
|
|
|
|
|
3364
|
|
|
1
|
|
|
|
|
123
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
12
|
use base qw(Exporter); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1538
|
|
7
|
|
|
|
|
|
|
our @EXPORT_OK = qw(vars_from_hash vars_from_getters); |
8
|
|
|
|
|
|
|
our $VERSION = "0.02"; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub vars_from_hash { |
11
|
1
|
|
|
1
|
1
|
15
|
my $h = shift; |
12
|
1
|
|
|
|
|
5
|
for my $i (0..$#_) { |
13
|
3
|
|
|
|
|
20
|
my $key = var_name(1, \$_[$i]); |
14
|
3
|
50
|
|
|
|
10
|
ord($key) == ord('$') or die __PACKAGE__.": must be scalar!"; |
15
|
3
|
|
|
|
|
7
|
$key = substr($key,1); |
16
|
3
|
|
|
|
|
10
|
$_[$i] = $h->{$key}; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub vars_from_getters { |
21
|
1
|
|
|
1
|
1
|
1465
|
my $prefix = shift; |
22
|
1
|
|
|
|
|
2
|
my $obj; |
23
|
1
|
50
|
|
|
|
6
|
if (ref $prefix) { |
24
|
0
|
|
|
|
|
0
|
$obj = $prefix; |
25
|
0
|
|
|
|
|
0
|
$prefix = ""; |
26
|
|
|
|
|
|
|
} else { |
27
|
1
|
|
|
|
|
2
|
$obj = shift; |
28
|
|
|
|
|
|
|
} |
29
|
1
|
|
|
|
|
5
|
for my $i (0..$#_) { |
30
|
3
|
|
|
|
|
24
|
my $key = var_name(1, \$_[$i]); |
31
|
3
|
50
|
|
|
|
13
|
ord($key) == ord('$') or die __PACKAGE__.": must be scalar!"; |
32
|
3
|
|
|
|
|
6
|
$key = $prefix . substr($key,1); |
33
|
3
|
50
|
|
|
|
90
|
$_[$i] = $obj->$key if ($obj->can($key)) |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
1; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
__END__ |