| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Enbld::Target::Attribute; |
|
2
|
|
|
|
|
|
|
|
|
3
|
19
|
|
|
19
|
|
1145
|
use strict; |
|
|
19
|
|
|
|
|
31
|
|
|
|
19
|
|
|
|
|
650
|
|
|
4
|
19
|
|
|
19
|
|
102
|
use warnings; |
|
|
19
|
|
|
|
|
30
|
|
|
|
19
|
|
|
|
|
564
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
19
|
|
|
19
|
|
18507
|
use Module::Load::Conditional qw/can_load/; |
|
|
19
|
|
|
|
|
677344
|
|
|
|
19
|
|
|
|
|
12724
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Enbld::Exception; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
|
11
|
1404
|
|
|
1404
|
0
|
3293
|
my ( $class, $name, $param ) = @_; |
|
12
|
|
|
|
|
|
|
|
|
13
|
1404
|
100
|
|
|
|
2944
|
if ( ! $name ) { |
|
14
|
1
|
|
|
|
|
5
|
Enbld::Exception->throw( "'$class' requires name" ); |
|
15
|
|
|
|
|
|
|
} |
|
16
|
|
|
|
|
|
|
|
|
17
|
1403
|
|
|
|
|
2870
|
my $module = "Enbld::Target::Attribute::$name"; |
|
18
|
|
|
|
|
|
|
|
|
19
|
1403
|
100
|
|
|
|
7985
|
can_load( modules => { $module => 0 } ) or |
|
20
|
|
|
|
|
|
|
Enbld::Exception->throw( "Attribute '$name' is invalid name" ); |
|
21
|
|
|
|
|
|
|
|
|
22
|
1402
|
|
|
|
|
185164
|
my $self = { |
|
23
|
|
|
|
|
|
|
attributes => undef, |
|
24
|
|
|
|
|
|
|
value => undef, |
|
25
|
|
|
|
|
|
|
callback => undef, |
|
26
|
|
|
|
|
|
|
is_evaluated => undef, |
|
27
|
|
|
|
|
|
|
}; |
|
28
|
|
|
|
|
|
|
|
|
29
|
1402
|
|
|
|
|
6209
|
bless $self, $module; |
|
30
|
|
|
|
|
|
|
|
|
31
|
1402
|
|
|
|
|
9178
|
$self->initialize( $param ); |
|
32
|
|
|
|
|
|
|
|
|
33
|
1384
|
|
|
|
|
5496
|
return $self; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub initialize { |
|
37
|
714
|
|
|
714
|
0
|
1043
|
my ( $self, $param ) = @_; |
|
38
|
|
|
|
|
|
|
|
|
39
|
714
|
100
|
|
|
|
1892
|
if ( ref( $param ) eq 'CODE' ) { |
|
40
|
44
|
|
|
|
|
97
|
$self->{callback} = $param; |
|
41
|
44
|
|
|
|
|
116
|
return $self; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
670
|
|
|
|
|
1484
|
$self->{value} = $param; |
|
45
|
670
|
|
|
|
|
1156
|
$self->{is_evaluated}++; |
|
46
|
670
|
|
|
|
|
1684
|
return $self; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub validate { |
|
50
|
1135
|
|
|
1135
|
0
|
1486
|
my ( $self, $string ) = @_; |
|
51
|
|
|
|
|
|
|
|
|
52
|
1135
|
100
|
|
|
|
2336
|
if ( ! $string ) { |
|
53
|
13
|
|
|
|
|
37
|
my $type = ref( $self ); |
|
54
|
13
|
|
|
|
|
59
|
$type =~ s/.*:://; |
|
55
|
13
|
|
|
|
|
90
|
Enbld::Exception->throw( "Attribute '$type' is empty string" ); |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
1122
|
100
|
|
|
|
2251
|
if ( ref( $string ) ) { |
|
59
|
15
|
|
|
|
|
40
|
my $type = ref( $self ); |
|
60
|
15
|
|
|
|
|
1157
|
$type =~ s/.*:://; |
|
61
|
15
|
|
|
|
|
105
|
Enbld::Exception->throw( "Attribute '$type' isn't scalar value" ); |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
1107
|
|
|
|
|
2286
|
return $string; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub evaluate { |
|
68
|
1509
|
|
|
1509
|
0
|
2187
|
my $self = shift; |
|
69
|
|
|
|
|
|
|
|
|
70
|
1509
|
100
|
|
|
|
6568
|
return $self->{value} if $self->{is_evaluated}; |
|
71
|
|
|
|
|
|
|
|
|
72
|
316
|
|
|
|
|
1462
|
$self->{value} = $self->{callback}->( $self->{attributes} ); |
|
73
|
315
|
|
|
|
|
1027
|
$self->{is_evaluated}++; |
|
74
|
|
|
|
|
|
|
|
|
75
|
315
|
|
|
|
|
663
|
return $self->{value}; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub to_value { |
|
79
|
1306
|
|
|
1306
|
0
|
2209
|
my $self = shift; |
|
80
|
|
|
|
|
|
|
|
|
81
|
1306
|
|
|
|
|
4802
|
my $value = $self->evaluate; |
|
82
|
|
|
|
|
|
|
|
|
83
|
1305
|
100
|
100
|
|
|
5538
|
return '' if ( ( ! $value ) && $self->is_omitable ); |
|
84
|
|
|
|
|
|
|
|
|
85
|
1182
|
|
|
|
|
9043
|
$self->validate( $value ); |
|
86
|
|
|
|
|
|
|
|
|
87
|
1133
|
|
|
|
|
15737
|
return $value; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub is_omitable { |
|
91
|
13
|
|
|
13
|
0
|
69
|
return; # if attribute is not omitable, override this method in sub class. |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub link_to_collector { |
|
95
|
1384
|
|
|
1384
|
0
|
2133
|
my ( $self, $collector ) = @_; |
|
96
|
|
|
|
|
|
|
|
|
97
|
1384
|
|
|
|
|
5095
|
$self->{attributes} = $collector; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |