OpenInteract2/ContentGenerator/TemplateSource.pm

filter: Statementstmt 31.6% 19 / 60 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 71.4% 5 / 7 Podpod 0.0% 0 / 2 totaltotal 20.0% 24 / 120 CC 20 SCAR 56.3
CC
20
Cov
18%
identify
380.0
load_source
6.0
BEGIN
1.0
CRAP 278.3
↑ Summary OpenInteract2/Action/Common.pm »
1 package OpenInteract2::ContentGenerator::TemplateSource;
2  
3 # $Id: TemplateSource.pm,v 1.15 2005/03/17 14:58:01 sjn Exp $
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Log::Log4perl qw( get_logger );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use OpenInteract2::Constants qw( :log );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use OpenInteract2::Context qw( CTX );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use OpenInteract2::Exception qw( oi_error );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 $OpenInteract2::ContentGenerator::TemplateSource::VERSION = sprintf("%d.%02d", q$Revision: 1.15 $ =~ /(\d+)\.(\d+)/);
12  
13 1 my $REQUIRED = 0;
14  
15 1 my ( $log );
16  
17 0 ▶sub identify {
Subroutine identify: not called CC=19 SCAR=59.4
Pod undocumented
18 0 my ( $class, $template_source ) = @_;
19 0 ▶ $log ||= get_logger( LOG_TEMPLATE );
Condition0%0/3
$log ||= get_logger("OI2.TEMPLATE")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log ||= get_logger("OI2.TEMPLATE")
$log get_logger("OI2.TEMPLATE")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.TEMPLATE")
ABresult
1X1
011
000
20 0 ▶ $REQUIRED || require OpenInteract2::SiteTemplate && $REQUIRED++;
Branch: 1 branch
BranchTrueFalseTotal
$REQUIRED or require OpenInteract2::SiteTemplate and ++$REQUIRED 0 0 0
Condition0%0/6
$REQUIRED || require OpenInteract2::SiteTemplate && ++$REQUIRED
l!l&&r!l&&!r
000
require OpenInteract2::SiteTemplate and ++$REQUIRED
!ll&&!rl&&r
000
MC/DC0%0/3
$REQUIRED || require OpenInteract2::SiteTemplate && ++$REQUIRED
$REQUIRED require OpenInteract2::SiteTemplate ++$REQUIRED
Truth table0%0/4
A || B and C
A= $REQUIREDB= require OpenInteract2::SiteTemplateC= ++$REQUIRED
ABCresult
1XX1
0111
00X0
0100
21  
22 0 ▶ unless ( ref $template_source eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $template_source eq "HASH") 0 0 0
23 0 $log->error( "Template source not hashref: ", ref $template_source );
24 0 oi_error "Template source description must be passed as hashref";
25 }
26  
27 0 my ( $source_type, $source, $name );
28  
29 0 ▶ if ( my $key = $template_source->{message_key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $key = $template_source->{"message_key"}) 0 0 0
30 0 my $lh = CTX->request->language_handle;
31 0 my $template_name = $lh->maketext( $key );
32 0 ▶ unless ( $template_name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($template_name) 0 0 0
33 0 oi_error "No template found for message key '$key'";
34 }
35 0 $template_source->{name} = $template_name;
36 }
37  
38 # don't make this an elsif since the previous condition sets a
39 # template name
40  
41 0 ▶ if ( $template_source->{name} ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($template_source->{'name'}) { } 0 0 0
elsif ($template_source->{'text'}) { } 0 0 0
elsif ($template_source->{'filehandle'}) { } 0 0 0
elsif ($template_source->{'object'}) { } 0 0 0
elsif ($template_source->{'db'}) { } 0 0 0
42 0 $source_type = 'NAME';
43 0 $name = $template_source->{name};
44 0 $source = $name;
45 0 ▶ $log->is_debug &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("Source template from name [$source]") 0 0 0
46 $log->debug( "Source template from name [$source]" );
47 }
48  
49 elsif ( $template_source->{text} ) {
50 0 $source_type = 'STRING';
51 $source = ( ref $template_source->{text} eq 'SCALAR' )
52 ? $template_source->{text}
53 0 ▶ : \$template_source->{text};
Branch: 1 branch
BranchTrueFalseTotal
ref $template_source->{'text'} eq 'SCALAR' ? : 0 0 0
54 0 $name = '_anonymous_';
55 0 ▶ $log->is_debug &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("Source template from raw text") 0 0 0
56 $log->debug( "Source template from raw text" );
57 }
58  
59 elsif ( $template_source->{filehandle} ) {
60 0 $source_type = 'FILE';
61 0 $source = $template_source->{filehandle};
62 0 ▶ $log->is_debug &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("Source template from filehandle") 0 0 0
63 $log->debug( "Source template from filehandle" );
64 }
65  
66 elsif ( $template_source->{object} ) {
67 0 $source_type = 'STRING';
68 0 $source = \$template_source->{object}{template};
69 0 $name = $template_source->{object}->create_name;
70 0 ▶ $log->is_debug &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("Source template from template object [$name]") 0 0 0
71 $log->debug( "Source template from template object [$name]" );
72 }
73  
74 elsif ( $template_source->{db} ) {
75 0 oi_error "Please declare your template using the 'name = pkg::name' ",
76 "syntax rather than the 'db = name, package = pkg' one. ",
77 "(Given db: $template_source->{db}; ",
78 "$template_source->{package}";
79 }
80  
81 # Uh oh...
82  
83 else {
84 0 require Data::Dumper;
85 0 $log->error( "No template to process! Information given for ",
86 "source:\n", Data::Dumper->Dumper( $template_source ) );
87 0 oi_error "No template to process!";
88 }
89  
90 0 ▶ if ( $name and CTX->controller->can( 'add_template_used' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name and CTX()->controller->can("add_template_used")) 0 0 0
Condition0%0/3
$name and CTX()->controller->can("add_template_used")
!ll&&!rl&&r
000
MC/DC0%0/2
$name and CTX()->controller->can("add_template_used")
$name CTX()->controller->can("add_template_used")
Truth table0%0/3
A and B
A= $nameB= CTX()->controller->can("add_template_used")
ABresult
0X0
100
111
91 0 CTX->controller->add_template_used( $name );
92 }
93 0 return ( $source_type, $source );
94 }
95  
96 0 ▶sub load_source {
Subroutine load_source: not called CC=2 SCAR=17.9
Pod undocumented
97 0 my ( $class, $name ) = @_;
98 0 my $content_template = OpenInteract2::SiteTemplate->fetch( $name );
99 0 ▶ unless ( $content_template ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($content_template) 0 0 0
100 0 oi_error "Template with name [$name] not found.";
101 }
102 0 return ( $content_template->contents,
103 $content_template->full_filename,
104 $content_template->modified_on );
105 }
106  
107 1 1;
108  
109 __END__
↑ Summary OpenInteract2/Action/Common.pm »