line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Moonshine::Component; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
15830
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
38
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
561
|
use Moonshine::Element; |
|
1
|
|
|
|
|
27231
|
|
|
1
|
|
|
|
|
29
|
|
7
|
1
|
|
|
1
|
|
490
|
use Moonshine::Magic; |
|
1
|
|
|
|
|
41716
|
|
|
1
|
|
|
|
|
7
|
|
8
|
1
|
|
|
1
|
|
974
|
use Params::Validate qw(:all); |
|
1
|
|
|
|
|
7988
|
|
|
1
|
|
|
|
|
185
|
|
9
|
1
|
|
|
1
|
|
7
|
use Ref::Util qw(:all); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
186
|
|
10
|
1
|
|
|
1
|
|
4
|
use feature qw/switch/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
86
|
|
11
|
1
|
|
|
1
|
|
4
|
no if $] >= 5.017011, warnings => 'experimental::smartmatch'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
9
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
extends "UNIVERSAL::Object"; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
BEGIN { |
18
|
1
|
|
|
1
|
|
495
|
my $fields = $Moonshine::Element::HAS{"attribute_list"}->(); |
19
|
1
|
|
|
|
|
3
|
my %html_spec = map { $_ => 0 } @{$fields}, qw/data tag/; |
|
153
|
|
|
|
|
172
|
|
|
1
|
|
|
|
|
3
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has ( |
22
|
|
|
|
|
|
|
html_spec => sub { \%html_spec }, |
23
|
|
|
|
|
|
|
modifier_spec => sub { { } }, |
24
|
1
|
|
|
|
|
45
|
); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub validate_build { |
28
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
29
|
0
|
|
|
|
|
|
my %args = validate_with( |
30
|
|
|
|
|
|
|
params => $_[0], |
31
|
|
|
|
|
|
|
spec => { |
32
|
|
|
|
|
|
|
params => { type => HASHREF }, |
33
|
|
|
|
|
|
|
spec => { type => HASHREF }, |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my %html_spec = %{ $self->html_spec }; |
|
0
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my %html_params = (); |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my %modifier_spec = %{ $self->modifier_spec }; |
|
0
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my %modifier_params = (); |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my %combine = ( %{ $args{params} }, %{ $args{'spec'} } ); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
for my $key ( keys %combine ) { |
46
|
0
|
|
|
|
|
|
my $spec = $args{spec}->{$key}; |
47
|
0
|
0
|
|
|
|
|
if ( is_hashref($spec) ) { |
48
|
0
|
0
|
|
|
|
|
defined $spec->{build} and next; |
49
|
0
|
0
|
|
|
|
|
if ( exists $spec->{base} ) { |
50
|
0
|
|
|
|
|
|
my $param = delete $args{params}->{$key}; |
51
|
0
|
|
|
|
|
|
my $spec = delete $args{spec}->{$key}; |
52
|
0
|
0
|
|
|
|
|
$html_params{$key} = $param if $param; |
53
|
0
|
0
|
|
|
|
|
$html_spec{$key} = $spec if $spec; |
54
|
0
|
|
|
|
|
|
next; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
if ( exists $html_spec{$key} ) { |
|
|
0
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if ( defined $spec ) { |
60
|
0
|
|
|
|
|
|
$html_spec{$key} = delete $args{spec}->{$key}; |
61
|
|
|
|
|
|
|
} |
62
|
0
|
0
|
|
|
|
|
if ( exists $args{params}->{$key} ) { |
63
|
0
|
|
|
|
|
|
$html_params{$key} = delete $args{params}->{$key}; |
64
|
|
|
|
|
|
|
} |
65
|
0
|
|
|
|
|
|
next; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
elsif ( exists $modifier_spec{$key} ) { |
68
|
0
|
0
|
|
|
|
|
if ( defined $spec ) { |
69
|
0
|
|
|
|
|
|
$modifier_spec{$key} = delete $args{spec}->{$key}; |
70
|
|
|
|
|
|
|
} |
71
|
0
|
0
|
|
|
|
|
if ( exists $args{params}->{$key} ) { |
72
|
0
|
|
|
|
|
|
my $params = $args{params}->{$key}; |
73
|
0
|
|
|
|
|
|
$modifier_params{$key} = delete $args{params}->{$key}; |
74
|
|
|
|
|
|
|
} |
75
|
0
|
|
|
|
|
|
next; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
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
|
0
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
my %modifier = validate_with( |
90
|
|
|
|
|
|
|
params => \%modifier_params, |
91
|
|
|
|
|
|
|
spec => \%modifier_spec, |
92
|
|
|
|
|
|
|
); |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
for my $element (qw/before_element after_element children/) { |
95
|
0
|
0
|
|
|
|
|
if ( defined $modifier{$element} ) { |
96
|
0
|
|
|
|
|
|
my @elements = $self->build_elements( @{ $modifier{$element} } ); |
|
0
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
$base{$element} = \@elements; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
0
|
0
|
0
|
|
|
|
if (scalar keys %modifier and $self->can('modify')) { |
102
|
0
|
|
|
|
|
|
return $self->modify(\%base, \%build, \%modifier); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
return \%base, \%build, \%modifier; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub build_elements { |
109
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
110
|
0
|
|
|
|
|
|
my @elements_build_instructions = @_; |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
my @elements; |
113
|
0
|
|
|
|
|
|
for my $build (@elements_build_instructions) { |
114
|
0
|
|
|
|
|
|
my $element; |
115
|
0
|
0
|
0
|
|
|
|
if ( is_blessed_ref($build) and $build->isa('Moonshine::Element') ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
$element = $build; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
elsif ( my $action = delete $build->{action} ) { |
119
|
0
|
0
|
0
|
|
|
|
$self->can($action) and $element = $self->$action($build) |
120
|
|
|
|
|
|
|
or die "cannot find action - $action"; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
elsif ( defined $build->{tag} ) { |
123
|
0
|
|
|
|
|
|
$element = Moonshine::Element->new($build); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
else { |
126
|
|
|
|
|
|
|
my $error_string = |
127
|
0
|
|
|
|
|
|
join( ", ", map { "$_: $build->{$_}" } keys %{$build} ); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
die sprintf "no instructions to build the element: %s", |
129
|
|
|
|
|
|
|
$error_string; |
130
|
|
|
|
|
|
|
} |
131
|
0
|
|
|
|
|
|
push @elements, $element; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
return @elements; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
1; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
__END__ |