blib/lib/Catalyst/View/HTML/Zoom.pm

filter: Statementstmt 95.6% 88 / 92 Branchbran 65.0% 13 / 20 Conditioncond 57.1% 8 / 14 MC/DCmcdc 11.1% 1 / 9 Subroutinesub 100% 23 / 23 Podpod 100% 2 / 2 totaltotal 84.3% 135 / 160 CC 16 SCAR 10.6
CC
16
Cov
87%
_template_path_part_from_context
9.4
process
3.3
_build_renderer_from
3.0
CRAP 2.9
↑ Summary
1 package Catalyst::View::HTML::Zoom;
2 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 $Catalyst::View::HTML::Zoom::VERSION = '0.003';
4 }
5 # ABSTRACT: Catalyst view to HTML::Zoom
6  
7 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Class::MOP;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use HTML::Zoom;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Path::Class ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 3 extends 'Catalyst::View';
14 3 with 'Catalyst::Component::ApplicationAttribute';
15  
16 3 has template_extension => (
17 is => 'ro',
18 isa => 'Str',
19 predicate => 'has_template_extension',
20 );
21  
22 3 has content_type => (
23 is => 'ro',
24 isa => 'Str',
25 required => 1,
26 default => 'text/html; charset=utf-8',
27 );
28  
29 3 has root => (
30 is => 'ro',
31 lazy_build => 1,
32 );
33  
34 1 ▶sub _build_root {
Subroutine _build_root: called CC=1 SCAR=0.0
35 1 shift->_application->config->{root};
36 }
37  
38 7 ▶sub process {
Subroutine process: called CC=3 SCAR=12.0
Pod documented
39 7 my ($self, $c) = @_;
40 7 my $template_path_part = $self->_template_path_part_from_context($c);
41 7 ▶ if(my $out = $self->render($c, $template_path_part)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $out = $self->render($c, $template_path_part)) { } 7 0 7
42 7 $c->response->body($out);
43 7 ▶ $c->response->content_type($self->content_type)
Branch: 1 branch
BranchTrueFalseTotal
unless $c->response->content_type 0 7 7
44 unless ($c->response->content_type);
45 7 return 1;
46 } else {
47 0 $c->log->error("The template: $template_path_part returned no response");
48 0 return 0;
49 }
50 }
51  
52 7 ▶sub _template_path_part_from_context {
Subroutine _template_path_part_from_context: called CC=5 SCAR=22.5
53 7 my ($self, $c) = @_;
54 7 ▶ my $template_path_part = $c->stash->{template} || $c->action->private_path;
Condition66%2/3
$c->stash->{'template'} || $c->action->private_path
l!l&&r!l&&!r
430
MC/DC0%0/2
$c->stash->{'template'} || $c->action->private_path
$c->stash->{'template'} $c->action->private_path
Truth table66%2/3
A || B
A= $c->stash->{'template'}B= $c->action->private_path
ABresult
1X1
011
000
55 7 ▶ if ($self->has_template_extension) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_template_extension) 0 7 7
56 0 my $ext = $self->template_extension;
57 0 ▶ $template_path_part = $template_path_part . '.' . $ext
Branch: 1 branch
BranchTrueFalseTotal
unless $template_path_part =~ /\.$ext$/ or ref $template_path_part 0 0 0
Condition0%0/3
$template_path_part =~ /\.$ext$/ or ref $template_path_part
l!l&&r!l&&!r
000
MC/DC0%0/2
$template_path_part =~ /\.$ext$/ or ref $template_path_part
$template_path_part =~ /\.$ext$/ ref $template_path_part
Truth table0%0/3
A or B
A= $template_path_part =~ /\.$ext$/B= ref $template_path_part
ABresult
1X1
011
000
58 unless $template_path_part =~ /\.$ext$/ || ref $template_path_part;
59 }
60 7 return $template_path_part;
61 }
62  
63 8 ▶sub render {
Subroutine render: called CC=2 SCAR=6.9
Pod documented
64 8 my ($self, $c, $template_path_part, $args, $code) = @_;
65 8 ▶ my $vars = {$args ? %{ $args } : %{ $c->stash }};
Branch: 1 branch
BranchTrueFalseTotal
$args ? : 1 7 8
66 8 my $zoom = $self->_build_zoom_from($template_path_part);
67 8 my $renderer = $self->_build_renderer_from($c, $code);
68 8 return $renderer->($zoom, $vars)->to_html;
69 }
70  
71 8 ▶sub _build_renderer_from {
Subroutine _build_renderer_from: called CC=3 SCAR=11.0
72 8 my ($self, $c, $code) = @_;
73 8 ▶ if($code = $code ? $code : $c->stash->{zoom_do}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($code = $code ? $code : $c->stash->{'zoom_do'}) { } 1 7 8
$code ? : 0 8 8
74 1 $self->_build_renderer_from_coderef($code);
75 } else {
76 7 $self->_build_renderer_from_zoomer_class($c);
77 }
78 }
79  
80 1 ▶sub _build_renderer_from_coderef {
Subroutine _build_renderer_from_coderef: called CC=1 SCAR=0.0
81 1 my ($self, $code) = @_;
82 1 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
83 1 my ($zoom, $vars) = @_;
84 1 return $code->($zoom, %$vars);
85 1 };
86 }
87  
88 7 ▶sub _build_renderer_from_zoomer_class {
Subroutine _build_renderer_from_zoomer_class: called CC=1 SCAR=0.0
89 7 my ($self, $c) = @_;
90 7 my $zoomer_class = $self->_zoomer_class_from_context($c);
91 7 my $zoomer = $self->_build_zoomer_from($zoomer_class);
92 7 my $action = $self->_target_action_from_context($c);
93 7 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
94 7 my ($zoom, $vars) = @_;
95 7 local $_ = $zoom;
96 7 return $zoomer->$action($vars);
97 7 };
98 }
99  
100 8 ▶sub _build_zoom_from {
Subroutine _build_zoom_from: called CC=2 SCAR=6.9
101 8 my ($self, $template_path_part) = @_;
102 8 ▶ if(ref $template_path_part) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $template_path_part) { } 1 7 8
103 1 return $self->_build_zoom_from_html($$template_path_part);
104 } else {
105 7 my $template_abs_path = $self->_template_abs_path_from($template_path_part);
106 7 return $self->_build_zoom_from_file($template_abs_path);
107 }
108 }
109  
110 1 ▶sub _build_zoom_from_html {
Subroutine _build_zoom_from_html: called CC=1 SCAR=0.0
111 1 my ($self, $html) = @_;
112 1 $self->_debug_log("Building HTML::Zoom from direct HTML");
113 1 HTML::Zoom->from_html($html);
114 }
115  
116 7 ▶sub _build_zoom_from_file {
Subroutine _build_zoom_from_file: called CC=1 SCAR=0.0
117 7 my ($self, $file) = @_;
118 7 $self->_debug_log("Building HTML::Zoom from file $file");
119 7 HTML::Zoom->from_file($file);
120 }
121  
122 7 ▶sub _template_abs_path_from {
Subroutine _template_abs_path_from: called CC=1 SCAR=0.0
123 7 my ($self, $template_path_part) = @_;
124 7 Path::Class::dir($self->root, $template_path_part);
125 }
126  
127 7 ▶sub _zoomer_class_from_context {
Subroutine _zoomer_class_from_context: called CC=3 SCAR=11.0
128 7 my ($self, $c) = @_;
129 7 my $controller = $c->controller->meta->name;
130 7 $controller =~ s/^.*::Controller::(.*)$/$1/;
131 7 my $zoomer_class = do {
132 $c->stash->{zoom_class} ||
133 7 ▶ join('::', ($self->meta->name, $controller));
Condition66%2/3
$c->stash->{'zoom_class'} || join('::', ($self->meta->name, $controller))
l!l&&r!l&&!r
250
MC/DC0%0/2
$c->stash->{'zoom_class'} || join('::', ($self->meta->name, $controller))
$c->stash->{'zoom_class'} join('::', ($self->meta->name, $controller))
Truth table66%2/3
A || B
A= $c->stash->{'zoom_class'}B= join('::', ($self->meta->name, $controller))
ABresult
1X1
011
000
134 };
135 7 ▶ $zoomer_class = ref($self) . $zoomer_class
Branch: 1 branch
BranchTrueFalseTotal
if $zoomer_class =~ /^::/ 1 6 7
136 if $zoomer_class=~m/^::/;
137 7 $self->_debug_log("Using View Class: $zoomer_class");
138 7 Class::MOP::load_class($zoomer_class);
139 7 return $zoomer_class;
140 }
141  
142 7 ▶sub _build_zoomer_from {
Subroutine _build_zoomer_from: called CC=2 SCAR=6.9
143 7 my ($self, $zoomer_class) = @_;
144 7 my $key = $zoomer_class;
145 7 $key =~s/^.+::(View)/$1/;
146 7 ▶ my %args = %{$self->_application->config->{$key} || {}};
Condition100%2/2
$self->_application->config->{$key} || {}
l!l
16
MC/DC100%1/1
$self->_application->config->{$key} || {}
$self->_application->config->{$key}
Truth table100%2/2
A
A= $self->_application->config->{$key}
Aresult
11
00
147 7 return $zoomer_class->new(%args);
148 }
149  
150 7 ▶sub _target_action_from_context {
Subroutine _target_action_from_context: called CC=2 SCAR=7.1
151 7 my ($self, $c) = @_;
152 return $c->stash->{zoom_action}
153 7 ▶ || $c->action->name;
Condition66%2/3
$c->stash->{'zoom_action'} || $c->action->name
l!l&&r!l&&!r
340
MC/DC0%0/2
$c->stash->{'zoom_action'} || $c->action->name
$c->stash->{'zoom_action'} $c->action->name
Truth table66%2/3
A || B
A= $c->stash->{'zoom_action'}B= $c->action->name
ABresult
1X1
011
000
154 }
155  
156 15 ▶sub _debug_log {
Subroutine _debug_log: called CC=2 SCAR=7.2
157 15 my ($self, $message) = @_;
158 15 ▶ $self->_application->log->debug($message)
Branch: 1 branch
BranchTrueFalseTotal
if $self->_application->debug 0 15 15
159 if $self->_application->debug;
160 }
161  
162 3 __PACKAGE__->meta->make_immutable;
163  
164  
165  
166 __END__
↑ Summary