File Coverage

blib/lib/Plack/App/Tags/HTML.pm
Criterion Covered Total %
statement 56 63 88.8
branch 13 20 65.0
condition n/a
subroutine 12 12 100.0
pod n/a
total 81 95 85.2


line stmt bran cond sub pod time code
1             package Plack::App::Tags::HTML;
2              
3 5     5   211115 use base qw(Plack::Component::Tags::HTML);
  5         30  
  5         2556  
4 5     5   349715 use strict;
  5         14  
  5         110  
5 5     5   27 use warnings;
  5         11  
  5         127  
6              
7 5     5   26 use English;
  5         12  
  5         35  
8 5     5   2402 use Error::Pure qw(err);
  5         14  
  5         216  
9 5     5   28 use Plack::Util::Accessor qw(component constructor_args data data_css data_init);
  5         18  
  5         39  
10 5     5   2702 use Symbol::Get;
  5         8837  
  5         2443  
11              
12             our $VERSION = 0.12;
13              
14             sub _css {
15 4     4   998 my $self = shift;
16              
17 4 50       32 if ($self->{'_component'}->can('process_css')) {
18 4         10 my @data_css;
19 4 50       16 if (defined $self->data_css) {
20 0         0 push @data_css, @{$self->data_css};
  0         0  
21             }
22              
23 4         45 $self->{'_component'}->process_css(@data_css);
24             }
25              
26 4         30 return;
27             }
28              
29             sub _loaded_component {
30 4     4   13 my ($self, $component) = @_;
31              
32 4         10 my @names = eval {
33 4         27 Symbol::Get::get_names($component);
34             };
35 4 100       218 if ($EVAL_ERROR) {
36 3         14 return 0;
37             }
38              
39 1         4 return 1;
40             }
41              
42             sub _prepare_app {
43 4     4   74028 my $self = shift;
44              
45 4         32 $self->SUPER::_prepare_app();
46              
47 4         3533 my %p = (
48             'css' => $self->css,
49             'tags' => $self->tags,
50             );
51              
52 4         49 my $component = $self->component;
53 4 100       28 if (! $self->_loaded_component($component)) {
54 3         210 eval "require $component;";
55 3 50       1092 if ($EVAL_ERROR) {
56 0         0 err "Cannot load component '$component'.",
57             'Error', $EVAL_ERROR;
58             }
59             }
60             $self->{'_component'} = $component->new(
61             %p,
62             defined $self->constructor_args ? (
63 4 50       30 %{$self->constructor_args},
  0         0  
64             ) : (),
65             );
66 4 50       317 if (! $self->{'_component'}->isa('Tags::HTML')) {
67 0         0 err "Component must be a instance of 'Tags::HTML' class.";
68             }
69              
70 4         16 return;
71             }
72              
73             sub _process_actions {
74 4     4   90 my $self = shift;
75              
76 4 50       52 if ($self->{'_component'}->can('init')) {
77 4         14 my @data = ();
78 4 100       17 if (defined $self->data_init) {
79 1         24 push @data, @{$self->data_init};
  1         3  
80             }
81 4         34 $self->{'_component'}->init(@data);
82             }
83              
84 4         59 return;
85             }
86              
87             sub _tags_middle {
88 4     4   7935 my $self = shift;
89              
90 4         8 my @data;
91 4 50       17 if (defined $self->data) {
92 0         0 push @data, @{$self->data};
  0         0  
93             }
94 4         55 $self->{'_component'}->process(@data);
95              
96 4         1172 return;
97             }
98              
99             1;
100              
101             __END__