line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sub::Talisman::Struct; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
30781
|
use 5.012; |
|
2
|
|
|
|
|
8
|
|
4
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
42
|
|
5
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
83
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
BEGIN { |
8
|
2
|
|
|
2
|
|
7
|
$Sub::Talisman::Struct::AUTHORITY = 'cpan:TOBYINK'; |
9
|
2
|
|
|
|
|
35
|
$Sub::Talisman::Struct::VERSION = '0.006'; |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
739
|
use Sub::Talisman (); |
|
2
|
|
|
|
|
35177
|
|
|
2
|
|
|
|
|
55
|
|
13
|
2
|
|
|
2
|
|
874
|
use MooX::Struct 0.016 (); |
|
2
|
|
|
|
|
185390
|
|
|
2
|
|
|
|
|
62
|
|
14
|
2
|
|
|
2
|
|
16
|
use Carp qw( confess ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
81
|
|
15
|
2
|
|
|
2
|
|
13
|
use Exporter::Tiny qw( mkopt ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
15
|
|
16
|
2
|
|
|
2
|
|
472
|
use namespace::clean; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
15
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our @ISA = qw( Sub::Talisman ); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub import |
21
|
|
|
|
|
|
|
{ |
22
|
4
|
|
|
4
|
|
298
|
my $class = shift; |
23
|
4
|
|
|
|
|
11
|
my $caller = caller; |
24
|
|
|
|
|
|
|
|
25
|
4
|
|
|
|
|
7
|
foreach my $arg (@{ mkopt \@_ }) |
|
4
|
|
|
|
|
13
|
|
26
|
|
|
|
|
|
|
{ |
27
|
7
|
|
|
|
|
110
|
my ($atr, $str) = @$arg; |
28
|
7
|
|
|
|
|
32
|
$class->setup_for($caller => { |
29
|
|
|
|
|
|
|
attribute => $atr, |
30
|
|
|
|
|
|
|
struct => $str, |
31
|
|
|
|
|
|
|
}); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my %PROCESSORS; |
36
|
|
|
|
|
|
|
my %STRUCTS; |
37
|
|
|
|
|
|
|
sub setup_for |
38
|
|
|
|
|
|
|
{ |
39
|
7
|
|
|
7
|
1
|
21
|
my ($class, $caller, $opts) = @_; |
40
|
7
|
|
|
|
|
31
|
$class->SUPER::setup_for($caller, $opts); |
41
|
7
|
|
66
|
|
|
2658
|
my $proc = $PROCESSORS{$caller} //= 'MooX::Struct::Processor'->new; |
42
|
|
|
|
|
|
|
my $struct = $proc->make_sub( |
43
|
|
|
|
|
|
|
$opts->{attribute}, |
44
|
7
|
|
100
|
|
|
4488
|
$opts->{struct} || [], |
45
|
|
|
|
|
|
|
); |
46
|
7
|
|
|
|
|
340
|
$STRUCTS{"$caller\::$opts->{attribute}"} = $struct; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _process_params |
50
|
|
|
|
|
|
|
{ |
51
|
15
|
|
|
15
|
|
16593
|
my ($class, $attr, $params) = @_; |
52
|
|
|
|
|
|
|
|
53
|
15
|
|
|
|
|
31
|
my %new; |
54
|
15
|
100
|
|
|
|
27
|
my @p = @{ $params || [] }; |
|
15
|
|
|
|
|
75
|
|
55
|
15
|
|
|
|
|
61
|
my @f = $STRUCTS{$attr}->()->FIELDS; |
56
|
15
|
100
|
|
|
|
9384
|
confess "Too many parameters for attribute $attr" if @p > @f; |
57
|
14
|
|
|
|
|
44
|
for my $i ( 0 .. $#p ) |
58
|
|
|
|
|
|
|
{ |
59
|
8
|
|
|
|
|
24
|
$new{ $f[$i] } = $p[$i]; |
60
|
|
|
|
|
|
|
} |
61
|
14
|
|
|
|
|
27
|
my $obj = eval { $STRUCTS{$attr}->()->new(%new) }; |
|
14
|
|
|
|
|
35
|
|
62
|
14
|
100
|
|
|
|
9572
|
return $obj if $obj; |
63
|
3
|
|
|
|
|
12
|
chomp(my $msg = $@); |
64
|
3
|
|
|
|
|
935
|
$msg =~ s{ at \(.+?\) line \d+\.?}{}; |
65
|
3
|
|
|
|
|
470
|
confess $msg; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__END__ |