WebApp/Template/Factory.pm

filter: Statementstmt 97.2% 35 / 36 Branchbran 75.0% 6 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 80.0% 4 / 5 totaltotal 93.1% 54 / 58 CC 5 SCAR 5.9
CC
5
Cov
93%
get_template_file
3.2
directory
2.0
processor
2.0
CRAP 1.8
« WebApp/Factory.pm ↑ Summary WebApp/Template.pm »
1 =head1 NAME
2  
3 OpenFrame::WebApp::Template::Factory - a factory for various types of template
4 wrappers.
5  
6 =head1 SYNOPSIS
7  
8 use OpenFrame::WebApp::Template::Factory;
9  
10 my $tf = new OpenFrame::WebApp::Template::Factory()
11 ->type( 'tt2' )
12 ->directory( $local_dir ) # optional
13 ->processor( new Template( ... ) ); # optional
14  
15 my $tmpl = $tf->new_template( $file, @new_args );
16  
17 =cut
18  
19 package OpenFrame::WebApp::Template::Factory;
20  
21 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 ▶use OpenFrame::WebApp::Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 1 our $VERSION = (split(/ /, '$Revision: 1.2 $'))[1];
27  
28 1 ▶use base qw ( OpenFrame::WebApp::Factory );
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 4 ▶sub directory {
Subroutine directory: called CC=2 SCAR=6.9
Pod documented
31 4 my $self = shift;
32 4 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 1 3 4
33 1 $self->{template_dir} = shift;
34 1 return $self;
35 } else {
36 3 return $self->{template_dir};
37 }
38 }
39  
40 3 ▶sub processor {
Subroutine processor: called CC=2 SCAR=6.9
Pod documented
41 3 my $self = shift;
42 3 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 1 2 3
43 1 $self->{template_processor} = shift;
44 1 return $self;
45 } else {
46 2 return $self->{template_processor};
47 }
48 }
49  
50 2 ▶sub get_types_class {
Subroutine get_types_class: called CC=1 SCAR=0.0
Pod documented
51 2 my $self = shift;
52 2 return OpenFrame::WebApp::Template->types->{$self->type};
53 }
54  
55 1 ▶sub new_template {
Subroutine new_template: called CC=1 SCAR=0.0
Pod documented
56 1 my $self = shift;
57 1 my $path = shift;
58 1 $self->new_object( @_ )
59 ->file( $self->get_template_file($path) )
60 ->processor( $self->processor );
61 # $tmpl->process should check for undef processor
62 }
63  
64 ## get path to the template file
65 ## shamelessly stolen from OpenFrame::AppKit::Segment::TT2
66 1 ▶sub get_template_file {
Subroutine get_template_file: called CC=3 SCAR=11.6
Pod undocumented
67 1 my $self = shift;
68 1 my $path = shift;
69  
70 1 ▶ return $path unless ($self->directory);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->directory 0 1 1
71  
72 ## split up the path so we know where we are
73 1 my ($volume, $dirs, $file) = File::Spec->splitpath( $path );
74  
75 ## make sure we have a file
76 1 ▶ if (!$file) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($file) 0 1 1
77 0 $file = "index.html";
78 }
79  
80 ## get the reconstituted path, with index.html tagged on if
81 ## there was no file.
82 1 return File::Spec->catfile( $self->directory, $dirs, $file );
83 }
84  
85  
86 1 1;
87  
88 __END__
« WebApp/Factory.pm ↑ Summary WebApp/Template.pm »