Jifty/View/Declare/Handler.pm

filter: Statementstmt 31.2% 25 / 80 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 53.8% 7 / 13 Podpod 66.6% 4 / 6 totaltotal 25.1% 36 / 143 CC 17 SCAR 29.4
CC
17
Cov
22%
config
42.0
show
30.0
template_stack
20.0
CRAP 18.9
« Jifty/Web/Session/ClientSide.pm ↑ Summary Jifty/Notification.pm »
1 package Jifty::View::Declare::Handler;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use base qw/Jifty::View Class::Accessor::Fast/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Template::Declare;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use HTML::Mason::Exceptions;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Exception::Class ( 'Template::Declare::Exception' =>
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 {description => 'error in a Template::Declare template', alias => 'error'});
12  
13 1 __PACKAGE__->mk_accessors(qw/root_class/);
14  
15 =head1 NAME
16  
17 Jifty::View::Declare::Handler - The Jifty view handler for Template::Declare
18  
19 =head1 METHODS
20  
21  
22 =head2 new
23  
24  
25 Initialize C<Template::Declare>. Passes all arguments to Template::Declare->init
26  
27 =cut
28  
29  
30 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
31 0 my $class = shift;
32 0 my $self = {};
33 0 bless $self,$class;
34
35 0 ▶ Template::Declare->init(@_ || $self->config());
Condition0%0/3
@_ || $self->config
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ || $self->config
@_ $self->config
Truth table0%0/3
A || B
A= @_B= $self->config
ABresult
1X1
011
000
36 0 return $self;
37 }
38  
39  
40 =head2 config
41  
42 =cut
43  
44 0 ▶sub config {
Subroutine config: not called CC=6 SCAR=37.4
Pod documented
45
46 my %config = (
47 0 ▶ %{ Jifty->config->framework('Web')->{'TemplateDeclareConfig'} ||{}},
Condition0%0/2
'Jifty'->config->framework('Web')->{'TemplateDeclareConfig'} || {}
l!l
00
MC/DC0%0/1
'Jifty'->config->framework('Web')->{'TemplateDeclareConfig'} || {}
'Jifty'->config->framework('Web')->{'TemplateDeclareConfig'}
Truth table0%0/2
A
A= 'Jifty'->config->framework('Web')->{'TemplateDeclareConfig'}
Aresult
11
00
48 );
49  
50 0 for my $plugin ( Jifty->plugins ) {
51 0 my $comp_root = $plugin->template_class;
52 0 Jifty::Util->require($comp_root);
53 0 ▶ next unless (defined $comp_root and $comp_root->isa('Template::Declare') and not Jifty::ClassLoader->autogenerated($comp_root));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $comp_root and $comp_root->isa("Template::Declare") and not "Jifty::ClassLoader"->autogenerated($comp_root) 0 0 0
Condition0%0/6
defined $comp_root and $comp_root->isa("Template::Declare") and not "Jifty::ClassLoader"->autogenerated($comp_root)
!ll&&!rl&&r
000
defined $comp_root and $comp_root->isa("Template::Declare")
!ll&&!rl&&r
000
MC/DC0%0/3
defined $comp_root and $comp_root->isa("Template::Declare") and not "Jifty::ClassLoader"->autogenerated($comp_root)
defined $comp_root $comp_root->isa("Template::Declare") not "Jifty::ClassLoader"->autogenerated($comp_root)
Truth table0%0/4
A and B and not(C)
A= defined $comp_rootB= $comp_root->isa("Template::Declare")C= not "Jifty::ClassLoader"->autogenerated($comp_root)
ABCresult
0XX0
10X0
1100
1111
54 0 $plugin->log->debug( "Plugin @{[ref($plugin)]}::View added as a Template::Declare root");
55 0 push @{ $config{roots} }, $comp_root ;
56 }
57  
58 0 push @{$config{roots}}, Jifty->config->framework('TemplateClass');
59 0 return %config;
60 }
61  
62 =head2 show TEMPLATENAME
63  
64 Render a template. Expects that the template and any jifty methods
65 called internally will end up being returned as a scalar, which we
66 then print to STDOUT
67  
68  
69 =cut
70  
71 0 ▶sub show {
Subroutine show: not called CC=5 SCAR=34.0
Pod documented
72 0 my $self = shift;
73 0 my $template = shift;
74 0 my $args = shift;
75  
76 0 Template::Declare->buffer( Jifty->handler->buffer );
77 0 eval {
78 Template::Declare::Tags::show_page(
79 $template,
80 $args || {
81 0 %{Jifty->web->request->arguments},
82 0 ▶ %{Jifty->web->request->template_arguments || {}},
Condition0%0/4
$args || {%{'Jifty'->web->request->arguments;}, %{'Jifty'->web->request->template_arguments or {};}}
l!l
00
'Jifty'->web->request->template_arguments || {}
l!l
00
MC/DC0%0/1
$args || {%{'Jifty'->web->request->arguments;}, %{'Jifty'->web->request->template_arguments or {};}}
$args
MC/DC0%0/1
'Jifty'->web->request->template_arguments || {}
'Jifty'->web->request->template_arguments
Truth table0%0/2
A
A= $args
Aresult
11
00
Truth table0%0/2
A
A= 'Jifty'->web->request->template_arguments
Aresult
11
00
83 },
84 );
85 };
86 0 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 0 0 0
87 0 ▶ $err->rethrow if ref $err;
Branch: 1 branch
BranchTrueFalseTotal
if ref $err 0 0 0
88 0 Template::Declare::Exception->throw($err);
89 }
90 0 return;
91 }
92  
93 =head2 template_exists TEMPLATENAME
94  
95 Given a template name, returns a valid template path (either
96 C<TEMPLATENAME> or C<TEMPLATENAME/index.html>) if the template is in
97 any of our Template::Declare template libraries. Otherwise returns
98 false.
99  
100 =cut
101  
102 0 ▶sub template_exists {
Subroutine template_exists: not called CC=3 SCAR=24.8
Pod documented
103 0 my $pkg = shift;
104 0 my $template = shift;
105 0 ▶ return $template if Template::Declare->resolve_template($template);
Branch: 1 branch
BranchTrueFalseTotal
if "Template::Declare"->resolve_template($template) 0 0 0
106 0 ▶ return "$template/index.html" if Template::Declare->resolve_template("$template/index.html");
Branch: 1 branch
BranchTrueFalseTotal
if "Template::Declare"->resolve_template("$template/index.html") 0 0 0
107 0 return undef;
108 }
109  
110 {
111 1 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
112  
113 0 ▶ sub HTML::Mason::Exception::template_stack {
Subroutine template_stack: not called CC=4 SCAR=30.0
Pod undocumented
114 0 my $self = shift;
115 0 ▶ return [] unless Jifty->handler and Jifty->handler->buffer;
Branch: 1 branch
BranchTrueFalseTotal
unless "Jifty"->handler and "Jifty"->handler->buffer 0 0 0
Condition0%0/3
"Jifty"->handler and "Jifty"->handler->buffer
!ll&&!rl&&r
000
MC/DC0%0/2
"Jifty"->handler and "Jifty"->handler->buffer
"Jifty"->handler "Jifty"->handler->buffer
Truth table0%0/3
A and B
A= "Jifty"->handlerB= "Jifty"->handler->buffer
ABresult
0X0
100
111
116 0 ▶ unless ($self->{_stack}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_stack"}) 0 0 0
117 0 $self->{_stack} = [reverse grep defined $_, map {$_->{from}} @{Jifty->handler->buffer->{stack}}],
118 }
119 0 return $self->{_stack};
120 }
121  
122 0 ▶ sub HTML::Mason::Exception::as_text {
Subroutine as_text: not called CC=2 SCAR=17.9
Pod undocumented
123 0 my ($self) = @_;
124 0 my $msg = $self->full_message;
125 0 my @template_stack = @{$self->template_stack};
126 0 ▶ if (@template_stack) {
Branch: 1 branch
BranchTrueFalseTotal
if (@template_stack) { } 0 0 0
127 0 my $stack = join("\n", map { sprintf(" [%s]", $_) } @template_stack);
128 0 return sprintf("%s\nTemplate stack:\n%s\n", $msg, $stack);
129 } else {
130 0 my $info = $self->analyze_error;
131 0 my $stack = join("\n", map { sprintf(" [%s:%d]", $_->filename, $_->line) } @{$info->{frames}});
132 0 return sprintf("%s\nStack:\n%s\n", $msg, $stack);
133 }
134 }
135 }
136  
137 1 package Template::Declare::Exception;
138 1 our @ISA = 'HTML::Mason::Exception';
139  
140 1 1;
« Jifty/Web/Session/ClientSide.pm ↑ Summary Jifty/Notification.pm »