line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Enbld::Target::Attribute; |
2
|
|
|
|
|
|
|
|
3
|
19
|
|
|
19
|
|
515
|
use strict; |
|
19
|
|
|
|
|
24
|
|
|
19
|
|
|
|
|
446
|
|
4
|
19
|
|
|
19
|
|
58
|
use warnings; |
|
19
|
|
|
|
|
16
|
|
|
19
|
|
|
|
|
347
|
|
5
|
|
|
|
|
|
|
|
6
|
19
|
|
|
19
|
|
58
|
use Carp; |
|
19
|
|
|
|
|
21
|
|
|
19
|
|
|
|
|
841
|
|
7
|
|
|
|
|
|
|
|
8
|
19
|
|
|
19
|
|
7744
|
use Module::Load; |
|
19
|
|
|
|
|
15248
|
|
|
19
|
|
|
|
|
92
|
|
9
|
19
|
|
|
19
|
|
9364
|
use Module::Load::Conditional qw/can_load/; |
|
19
|
|
|
|
|
352314
|
|
|
19
|
|
|
|
|
8216
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
1404
|
|
|
1404
|
0
|
2161
|
my ( $class, $name, $param ) = @_; |
13
|
|
|
|
|
|
|
|
14
|
1404
|
100
|
|
|
|
1976
|
if ( ! $name ) { |
15
|
1
|
|
|
|
|
362
|
require Enbld::Exception; |
16
|
1
|
|
|
|
|
5
|
croak( Enbld::Exception->new( "'$class' requires name" ) ); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
1403
|
|
|
|
|
1655
|
my $module = "Enbld::Target::Attribute::$name"; |
20
|
|
|
|
|
|
|
|
21
|
1403
|
100
|
|
|
|
4868
|
if ( can_load( modules => { $module => undef } ) ) { |
22
|
1402
|
|
|
|
|
97444
|
load $module; |
23
|
|
|
|
|
|
|
|
24
|
1402
|
|
|
|
|
72931
|
my $self = { |
25
|
|
|
|
|
|
|
attributes => undef, |
26
|
|
|
|
|
|
|
value => undef, |
27
|
|
|
|
|
|
|
callback => undef, |
28
|
|
|
|
|
|
|
is_evaluated => undef, |
29
|
|
|
|
|
|
|
}; |
30
|
|
|
|
|
|
|
|
31
|
1402
|
|
|
|
|
5069
|
bless $self, $module; |
32
|
|
|
|
|
|
|
|
33
|
1402
|
|
|
|
|
5370
|
$self->initialize( $param ); |
34
|
|
|
|
|
|
|
|
35
|
1384
|
|
|
|
|
3222
|
return $self; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
|
|
367
|
require Enbld::Exception; |
39
|
1
|
|
|
|
|
4
|
croak( Enbld::Exception->new( "Attribute '$name' is invalid name" ) ); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub initialize { |
44
|
714
|
|
|
714
|
0
|
720
|
my ( $self, $param ) = @_; |
45
|
|
|
|
|
|
|
|
46
|
714
|
100
|
|
|
|
1396
|
if ( ref( $param ) eq 'CODE' ) { |
47
|
44
|
|
|
|
|
57
|
$self->{callback} = $param; |
48
|
44
|
|
|
|
|
75
|
return $self; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
670
|
|
|
|
|
845
|
$self->{value} = $param; |
52
|
670
|
|
|
|
|
813
|
$self->{is_evaluated}++; |
53
|
670
|
|
|
|
|
835
|
return $self; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub validate { |
57
|
1135
|
|
|
1135
|
0
|
836
|
my ( $self, $string ) = @_; |
58
|
|
|
|
|
|
|
|
59
|
1135
|
100
|
|
|
|
1635
|
if ( ! $string ) { |
60
|
13
|
|
|
|
|
23
|
my $type = ref( $self ); |
61
|
13
|
|
|
|
|
77
|
$type =~ s/.*:://; |
62
|
13
|
|
|
|
|
55
|
require Enbld::Exception; |
63
|
13
|
|
|
|
|
65
|
croak( Enbld::Exception->new( "Attribute '$type' is empty string" )); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
1122
|
100
|
|
|
|
1484
|
if ( ref( $string ) ) { |
67
|
15
|
|
|
|
|
30
|
my $type = ref( $self ); |
68
|
15
|
|
|
|
|
55
|
$type =~ s/.*:://; |
69
|
|
|
|
|
|
|
|
70
|
15
|
|
|
|
|
38
|
my $err = "Attribute '$type' isn't scalar value"; |
71
|
15
|
|
|
|
|
385
|
require Enbld::Exception; |
72
|
15
|
|
|
|
|
57
|
croak( Enbld::Exception->new( $err, $string )); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
1107
|
|
|
|
|
1281
|
return $string; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub evaluate { |
79
|
1509
|
|
|
1509
|
0
|
1152
|
my $self = shift; |
80
|
|
|
|
|
|
|
|
81
|
1509
|
100
|
|
|
|
3894
|
return $self->{value} if $self->{is_evaluated}; |
82
|
|
|
|
|
|
|
|
83
|
316
|
|
|
|
|
829
|
$self->{value} = $self->{callback}->( $self->{attributes} ); |
84
|
315
|
|
|
|
|
455
|
$self->{is_evaluated}++; |
85
|
|
|
|
|
|
|
|
86
|
315
|
|
|
|
|
377
|
return $self->{value}; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub to_value { |
90
|
1306
|
|
|
1306
|
0
|
1228
|
my $self = shift; |
91
|
|
|
|
|
|
|
|
92
|
1306
|
|
|
|
|
2313
|
my $value = $self->evaluate; |
93
|
|
|
|
|
|
|
|
94
|
1305
|
100
|
100
|
|
|
3072
|
return '' if ( ( ! $value ) && $self->is_omitable ); |
95
|
|
|
|
|
|
|
|
96
|
1182
|
|
|
|
|
3654
|
$self->validate( $value ); |
97
|
|
|
|
|
|
|
|
98
|
1133
|
|
|
|
|
5256
|
return $value; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub is_omitable { |
102
|
13
|
|
|
13
|
0
|
61
|
return; # if attribute is not omitable, override this method in sub class. |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub link_to_collector { |
106
|
1384
|
|
|
1384
|
0
|
1197
|
my ( $self, $collector ) = @_; |
107
|
|
|
|
|
|
|
|
108
|
1384
|
|
|
|
|
1771
|
$self->{attributes} = $collector; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |