| 1 | package Plack::App::Tags::HTML; | ||||||||||
| 2 | |||||||||||
| 3 | 10 | ▶ | use base qw(Plack::Component::Tags::HTML); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 10 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 10 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 10 | ▶ | use English; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 10 | ▶ | use Error::Pure qw(err); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 10 | ▶ | use Plack::Util::Accessor qw(component constructor_args data data_css data_init data_prepare); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 10 | ▶ | use Symbol::Get; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 10 | our $VERSION = 0.19; | |||||||||
| 13 | |||||||||||
| 14 | 9 | ▶ | sub _css { | ||||||||
|
Subroutine
_css: called CC=2 SCAR=6.9
| |||||||||||
| 15 | 9 | my ($self, $env) = @_; | |||||||||
| 16 | |||||||||||
| 17 | 9 | my @data_css; | |||||||||
| 18 | 9 | ▶ | if (defined $self->data_css) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 1 | push @data_css, @{$self->data_css}; | |||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | 9 | $self->{'_component'}->process_css(@data_css); | |||||||||
| 23 | |||||||||||
| 24 | 9 | return; | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 11 | ▶ | sub _loaded_component { | ||||||||
|
Subroutine
_loaded_component: called CC=2 SCAR=6.9
| |||||||||||
| 28 | 11 | my ($self, $component) = @_; | |||||||||
| 29 | |||||||||||
| 30 | 11 | my @names = eval { | |||||||||
| 31 | 11 | Symbol::Get::get_names($component); | |||||||||
| 32 | }; | ||||||||||
| 33 | 11 | ▶ | if ($EVAL_ERROR) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 9 | return 0; | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 2 | return 1; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 11 | ▶ | sub _prepare_app { | ||||||||
|
Subroutine
_prepare_app: called CC=9 SCAR=22.2
| |||||||||||
| 41 | 11 | my $self = shift; | |||||||||
| 42 | |||||||||||
| 43 | 11 | $self->SUPER::_prepare_app(); | |||||||||
| 44 | |||||||||||
| 45 | 11 | my %p = ( | |||||||||
| 46 | 'css' => $self->css, | ||||||||||
| 47 | 'tags' => $self->tags, | ||||||||||
| 48 | ); | ||||||||||
| 49 | |||||||||||
| 50 | 11 | my $component = $self->component; | |||||||||
| 51 | 11 | ▶ | if (! $self->_loaded_component($component)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 9 | eval "require $component;"; | |||||||||
| 53 | 9 | ▶ | if ($EVAL_ERROR) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 2 | err "Cannot load component '$component'.", | |||||||||
| 55 | 'Error', $EVAL_ERROR; | ||||||||||
| 56 | } | ||||||||||
| 57 | } | ||||||||||
| 58 | $self->{'_component'} = $component->new( | ||||||||||
| 59 | %p, | ||||||||||
| 60 | defined $self->constructor_args ? ( | ||||||||||
| 61 | 9 | ▶ | %{$self->constructor_args}, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | ) : (), | ||||||||||
| 63 | ); | ||||||||||
| 64 | 9 | ▶ | if (! $self->{'_component'}->isa('Tags::HTML')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | 0 | err "Component must be a instance of 'Tags::HTML' class."; | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | # Init prepared data. | ||||||||||
| 69 | 9 | ▶ | if ($self->{'_component'}->can('prepare')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 9 | my @data = (); | |||||||||
| 71 | 9 | ▶ | if (defined $self->data_prepare) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | 1 | push @data, @{$self->data_prepare}; | |||||||||
| 73 | } | ||||||||||
| 74 | 9 | $self->{'_component'}->prepare(@data); | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | # Copy CSS links from component to main object. | ||||||||||
| 78 | 9 | ▶ | if ($self->{'_component'}->can('css_src')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | 9 | $self->css_src($self->{'_component'}->css_src); | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | # Copy Javascript links from component to main object. | ||||||||||
| 83 | 9 | ▶ | if ($self->{'_component'}->can('script_js_src')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | 9 | $self->script_js_src($self->{'_component'}->script_js_src); | |||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | 9 | return; | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 9 | ▶ | sub _process_actions { | ||||||||
|
Subroutine
_process_actions: called CC=4 SCAR=13.9
| |||||||||||
| 91 | 9 | my ($self, $env) = @_; | |||||||||
| 92 | |||||||||||
| 93 | 9 | ▶ | if ($self->{'_component'}->can('init')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 94 | 9 | ▶ | if (defined $self->data_init) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 95 | 1 | $self->{'_component'}->init(@{$self->data_init}); | |||||||||
| 96 | } else { | ||||||||||
| 97 | 8 | $self->{'_component'}->init; | |||||||||
| 98 | } | ||||||||||
| 99 | } | ||||||||||
| 100 | |||||||||||
| 101 | # Copy Javascript code from component to main object. | ||||||||||
| 102 | 9 | ▶ | if ($self->{'_component'}->can('script_js')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 103 | 9 | $self->script_js($self->{'_component'}->script_js); | |||||||||
| 104 | } | ||||||||||
| 105 | |||||||||||
| 106 | # Init begin of page. | ||||||||||
| 107 | 9 | $self->SUPER::_process_actions($env); | |||||||||
| 108 | |||||||||||
| 109 | 9 | return; | |||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | 9 | ▶ | sub _tags_middle { | ||||||||
|
Subroutine
_tags_middle: called CC=2 SCAR=6.9
| |||||||||||
| 113 | 9 | my ($self, $env) = @_; | |||||||||
| 114 | |||||||||||
| 115 | 9 | my @data; | |||||||||
| 116 | 9 | ▶ | if (defined $self->data) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 117 | 2 | push @data, @{$self->data}; | |||||||||
| 118 | } | ||||||||||
| 119 | 9 | $self->{'_component'}->process(@data); | |||||||||
| 120 | |||||||||||
| 121 | 9 | return; | |||||||||
| 122 | } | ||||||||||
| 123 | |||||||||||
| 124 | 10 | 1; | |||||||||
| 125 | |||||||||||
| 126 | __END__ | ||||||||||