line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::WidgetValidator::WidgetContainer; |
2
|
45
|
|
|
45
|
|
248
|
use warnings; |
|
45
|
|
|
|
|
77
|
|
|
45
|
|
|
|
|
1561
|
|
3
|
45
|
|
|
45
|
|
233
|
use strict; |
|
45
|
|
|
|
|
79
|
|
|
45
|
|
|
|
|
1467
|
|
4
|
45
|
|
|
45
|
|
232
|
use base qw(Class::Accessor::Fast); |
|
45
|
|
|
|
|
94
|
|
|
45
|
|
|
|
|
375
|
|
5
|
45
|
|
|
45
|
|
42109
|
use UNIVERSAL::require; |
|
45
|
|
|
|
|
83784
|
|
|
45
|
|
|
|
|
447
|
|
6
|
45
|
|
|
45
|
|
42288
|
use Module::Pluggable search_path => ['HTML::WidgetValidator::Widget'], sub_name => 'all_widgets'; |
|
45
|
|
|
|
|
546563
|
|
|
45
|
|
|
|
|
401
|
|
7
|
45
|
|
|
45
|
|
49682
|
use List::MoreUtils qw(each_arrayref any); |
|
45
|
|
|
|
|
57877
|
|
|
45
|
|
|
|
|
4524
|
|
8
|
|
|
|
|
|
|
|
9
|
45
|
|
|
45
|
|
27124
|
use HTML::WidgetValidator::Result; |
|
45
|
|
|
|
|
118
|
|
|
45
|
|
|
|
|
379
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw(widgets)); |
12
|
|
|
|
|
|
|
my $widget_namespace = 'HTML::WidgetValidator::Widget::'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
1
|
|
|
1
|
1
|
4
|
my ($class, %args) = @_; |
16
|
1
|
|
|
|
|
15
|
my $self = $class->SUPER::new(\%args); |
17
|
1
|
50
|
|
|
|
15
|
unless( defined $args{widgets} ){ |
18
|
1
|
|
|
|
|
8
|
my @widgets = map { $_ =~ s/^$widget_namespace//; $_ } $self->all_widgets; |
|
48
|
|
|
|
|
18910
|
|
|
48
|
|
|
|
|
67
|
|
19
|
1
|
|
|
|
|
10
|
$self->widgets(\@widgets); |
20
|
|
|
|
|
|
|
} |
21
|
1
|
|
|
|
|
24
|
$self->build_tree; |
22
|
1
|
|
|
|
|
22
|
return $self; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub add { |
26
|
1
|
|
|
1
|
0
|
6
|
my ($self, @widgets) = @_; |
27
|
1
|
|
|
|
|
3
|
foreach( @widgets ){ |
28
|
48
|
|
|
|
|
103
|
my $module = $widget_namespace.$_; |
29
|
48
|
|
|
|
|
102
|
$self->add_tree($module) |
30
|
|
|
|
|
|
|
} |
31
|
1
|
|
|
|
|
2
|
push @{$self->{widgets}}, @widgets; |
|
1
|
|
|
|
|
18
|
|
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub add_tree { |
35
|
48
|
|
|
48
|
0
|
58
|
my $self = shift; |
36
|
48
|
|
|
|
|
55
|
my $module = shift; |
37
|
48
|
50
|
|
|
|
258
|
if( !$module->require ){ |
38
|
0
|
|
|
|
|
0
|
warn $@; |
39
|
0
|
|
|
|
|
0
|
return; |
40
|
|
|
|
|
|
|
} |
41
|
48
|
|
50
|
|
|
517
|
my $models = $module->models || []; |
42
|
48
|
|
|
|
|
368
|
foreach my $model ( @$models ){ |
43
|
75
|
50
|
33
|
|
|
191
|
next if ref $model ne 'ARRAY' || $#{$model} == -1; |
|
75
|
|
|
|
|
288
|
|
44
|
75
|
|
50
|
|
|
185
|
my $name = $model->[0]->{name} || next; |
45
|
75
|
100
|
|
|
|
200
|
$self->{pattern_tree}->{$name} = [] unless $self->{pattern_tree}->{$name}; |
46
|
75
|
|
|
|
|
72
|
push @{$self->{pattern_tree}->{$name}}, |
|
75
|
|
|
|
|
430
|
|
47
|
|
|
|
|
|
|
{ |
48
|
|
|
|
|
|
|
widget => $module, |
49
|
|
|
|
|
|
|
model => $model, |
50
|
|
|
|
|
|
|
}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub build_tree { |
55
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
56
|
1
|
|
|
|
|
3
|
$self->{pattern_tree} = {}; |
57
|
1
|
|
|
|
|
3
|
my @widgets = @{$self->widgets}; |
|
1
|
|
|
|
|
4
|
|
58
|
1
|
|
|
|
|
15
|
$self->add( @widgets ); |
59
|
1
|
|
|
|
|
8
|
$self->widgets( \@widgets ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub match { |
63
|
0
|
|
|
0
|
0
|
|
my ( $self, $elements, $html ) = @_; |
64
|
0
|
0
|
0
|
|
|
|
return if ref $elements ne 'ARRAY' || $#{$elements} == -1; |
|
0
|
|
|
|
|
|
|
65
|
0
|
|
0
|
|
|
|
my $models = $self->{pattern_tree}->{$elements->[0]->name || ''} || return; |
66
|
0
|
|
|
|
|
|
MODEL: foreach ( @$models ){ |
67
|
0
|
|
|
|
|
|
my $model = $_->{model}; |
68
|
0
|
0
|
|
|
|
|
next if( $#{$model} != $#{$elements} ); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my $ea = each_arrayref($model, $elements); |
70
|
0
|
|
|
|
|
|
while ( my ($m, $e) = $ea->() ){ |
71
|
0
|
0
|
|
|
|
|
next MODEL unless $e->compare($m); |
72
|
|
|
|
|
|
|
} |
73
|
0
|
|
|
|
|
|
return HTML::WidgetValidator::Result->new( |
74
|
|
|
|
|
|
|
widget => $_->{widget}, |
75
|
|
|
|
|
|
|
elements => $elements, |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
__END__ |