line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Moonshine::Component; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
69615
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
73
|
|
4
|
3
|
|
|
3
|
|
9
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
63
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
1313
|
use Moonshine::Element; |
|
3
|
|
|
|
|
62316
|
|
|
3
|
|
|
|
|
84
|
|
7
|
3
|
|
|
3
|
|
1376
|
use Moonshine::Magic; |
|
3
|
|
|
|
|
112889
|
|
|
3
|
|
|
|
|
18
|
|
8
|
3
|
|
|
3
|
|
1486
|
use Params::Validate qw(:all); |
|
3
|
|
|
|
|
6824
|
|
|
3
|
|
|
|
|
517
|
|
9
|
3
|
|
|
3
|
|
30
|
use Ref::Util qw(:all); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
582
|
|
10
|
3
|
|
|
3
|
|
14
|
use feature qw/switch/; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
252
|
|
11
|
3
|
|
|
3
|
|
11
|
no if $] >= 5.017011, warnings => 'experimental::smartmatch'; |
|
3
|
|
|
|
|
2
|
|
|
3
|
|
|
|
|
23
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
extends "UNIVERSAL::Object"; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
BEGIN { |
18
|
3
|
|
|
3
|
|
1203
|
my $fields = $Moonshine::Element::HAS{"attribute_list"}->(); |
19
|
3
|
|
|
|
|
9
|
my %html_spec = map { $_ => 0 } @{$fields}, qw/data tag/; |
|
447
|
|
|
|
|
523
|
|
|
3
|
|
|
|
|
7
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has ( |
22
|
|
|
|
|
|
|
html_spec => sub { \%html_spec }, |
23
|
|
|
|
|
|
|
modifier_spec => sub { { } }, |
24
|
3
|
|
|
|
|
86
|
); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub validate_build { |
28
|
332
|
|
|
332
|
0
|
444162
|
my $self = shift; |
29
|
332
|
|
|
|
|
4564
|
my %args = validate_with( |
30
|
|
|
|
|
|
|
params => $_[0], |
31
|
|
|
|
|
|
|
spec => { |
32
|
|
|
|
|
|
|
params => { type => HASHREF }, |
33
|
|
|
|
|
|
|
spec => { type => HASHREF }, |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
332
|
|
|
|
|
979
|
my %html_spec = %{ $self->html_spec }; |
|
332
|
|
|
|
|
643
|
|
38
|
332
|
|
|
|
|
1495
|
my %html_params = (); |
39
|
|
|
|
|
|
|
|
40
|
332
|
|
|
|
|
226
|
my %modifier_spec = %{ $self->modifier_spec }; |
|
332
|
|
|
|
|
551
|
|
41
|
332
|
|
|
|
|
394
|
my %modifier_params = (); |
42
|
|
|
|
|
|
|
|
43
|
332
|
|
|
|
|
220
|
my %combine = ( %{ $args{params} }, %{ $args{'spec'} } ); |
|
332
|
|
|
|
|
499
|
|
|
332
|
|
|
|
|
588
|
|
44
|
|
|
|
|
|
|
|
45
|
332
|
|
|
|
|
610
|
for my $key ( keys %combine ) { |
46
|
997
|
|
|
|
|
791
|
my $spec = $args{spec}->{$key}; |
47
|
997
|
100
|
|
|
|
1338
|
if ( is_hashref($spec) ) { |
48
|
333
|
50
|
|
|
|
486
|
defined $spec->{build} and next; |
49
|
333
|
50
|
|
|
|
430
|
if ( exists $spec->{base} ) { |
50
|
0
|
|
|
|
|
0
|
my $param = delete $args{params}->{$key}; |
51
|
0
|
|
|
|
|
0
|
my $spec = delete $args{spec}->{$key}; |
52
|
0
|
0
|
|
|
|
0
|
$html_params{$key} = $param if $param; |
53
|
0
|
0
|
|
|
|
0
|
$html_spec{$key} = $spec if $spec; |
54
|
0
|
|
|
|
|
0
|
next; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
997
|
100
|
|
|
|
1060
|
if ( exists $html_spec{$key} ) { |
|
|
50
|
|
|
|
|
|
59
|
995
|
100
|
|
|
|
1182
|
if ( defined $spec ) { |
60
|
663
|
|
|
|
|
689
|
$html_spec{$key} = delete $args{spec}->{$key}; |
61
|
|
|
|
|
|
|
} |
62
|
995
|
100
|
|
|
|
1264
|
if ( exists $args{params}->{$key} ) { |
63
|
332
|
|
|
|
|
410
|
$html_params{$key} = delete $args{params}->{$key}; |
64
|
|
|
|
|
|
|
} |
65
|
995
|
|
|
|
|
1077
|
next; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
elsif ( exists $modifier_spec{$key} ) { |
68
|
2
|
50
|
|
|
|
5
|
if ( defined $spec ) { |
69
|
2
|
|
|
|
|
3
|
$modifier_spec{$key} = delete $args{spec}->{$key}; |
70
|
|
|
|
|
|
|
} |
71
|
2
|
100
|
|
|
|
4
|
if ( exists $args{params}->{$key} ) { |
72
|
1
|
|
|
|
|
2
|
my $params = $args{params}->{$key}; |
73
|
1
|
|
|
|
|
2
|
$modifier_params{$key} = delete $args{params}->{$key}; |
74
|
|
|
|
|
|
|
} |
75
|
2
|
|
|
|
|
3
|
next; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
332
|
|
|
|
|
23670
|
my %base = validate_with( |
80
|
|
|
|
|
|
|
params => \%html_params, |
81
|
|
|
|
|
|
|
spec => \%html_spec, |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my %build = validate_with( |
85
|
|
|
|
|
|
|
params => $args{params}, |
86
|
|
|
|
|
|
|
spec => $args{spec}, |
87
|
332
|
|
|
|
|
3816
|
); |
88
|
|
|
|
|
|
|
|
89
|
332
|
|
|
|
|
1702
|
my %modifier = validate_with( |
90
|
|
|
|
|
|
|
params => \%modifier_params, |
91
|
|
|
|
|
|
|
spec => \%modifier_spec, |
92
|
|
|
|
|
|
|
); |
93
|
|
|
|
|
|
|
|
94
|
332
|
|
|
|
|
590
|
for my $element (qw/before_element after_element children/) { |
95
|
996
|
50
|
|
|
|
1450
|
if ( defined $modifier{$element} ) { |
96
|
0
|
|
|
|
|
0
|
my @elements = $self->build_elements( @{ $modifier{$element} } ); |
|
0
|
|
|
|
|
0
|
|
97
|
0
|
|
|
|
|
0
|
$base{$element} = \@elements; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
332
|
100
|
66
|
|
|
689
|
if (scalar keys %modifier and $self->can('modify')) { |
102
|
1
|
|
|
|
|
4
|
return $self->modify(\%base, \%build, \%modifier); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
331
|
|
|
|
|
3225
|
return \%base, \%build, \%modifier; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub build_elements { |
109
|
5
|
|
|
5
|
0
|
2942
|
my $self = shift; |
110
|
5
|
|
|
|
|
6
|
my @elements_build_instructions = @_; |
111
|
|
|
|
|
|
|
|
112
|
5
|
|
|
|
|
6
|
my @elements; |
113
|
5
|
|
|
|
|
8
|
for my $build (@elements_build_instructions) { |
114
|
5
|
|
|
|
|
4
|
my $element; |
115
|
5
|
100
|
66
|
|
|
35
|
if ( is_blessed_ref($build) and $build->isa('Moonshine::Element') ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
116
|
1
|
|
|
|
|
1
|
$element = $build; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
elsif ( my $action = delete $build->{action} ) { |
119
|
1
|
50
|
33
|
|
|
8
|
$self->can($action) and $element = $self->$action($build) |
120
|
|
|
|
|
|
|
or die "cannot find action - $action"; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
elsif ( defined $build->{tag} ) { |
123
|
1
|
|
|
|
|
10
|
$element = Moonshine::Element->new($build); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
else { |
126
|
|
|
|
|
|
|
my $error_string = |
127
|
2
|
|
|
|
|
3
|
join( ", ", map { "$_: $build->{$_}" } keys %{$build} ); |
|
3
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
5
|
|
128
|
2
|
|
|
|
|
20
|
die sprintf "no instructions to build the element: %s", |
129
|
|
|
|
|
|
|
$error_string; |
130
|
|
|
|
|
|
|
} |
131
|
3
|
|
|
|
|
1275
|
push @elements, $element; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
3
|
|
|
|
|
12
|
return @elements; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
1; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
__END__ |