blib/lib/Template/Preprocessor/TTML.pm

filter: Statementstmt 100% 44 / 44 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 14 / 14 Podpod 100% 2 / 2 totaltotal 100% 64 / 64 SCAR 11.0
CC
3
Cov
100%
_get_output
2.0
_mode_regular
2.0
BEGIN
1.0
CRAP 3.0
« Build ↑ Summary blib/lib/Template/Preprocessor/TTML/Base.pm »
1 package Template::Preprocessor::TTML;
2  
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use base 'Template::Preprocessor::TTML::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Template::Preprocessor::TTML::CmdLineProc;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 __PACKAGE__->mk_accessors(
12 qw(
13 argv
14 opts
15 )
16 );
17  
18  
19  
20 sub initialize
21 {
22 10 ▶ my $self = shift;
Subroutine initialize: called CC=1 SCAR=0.0
Pod documented
23 10 my %args = (@_);
24 10 $self->argv( [ @{ $args{'argv'} } ] );
25  
26 10 return 0;
27 }
28  
29  
30 sub _calc_opts
31 {
32 10 ▶ my $self = shift;
Subroutine _calc_opts: called CC=1 SCAR=0.0
33 10 my $cmd_line =
34 Template::Preprocessor::TTML::CmdLineProc->new( argv => $self->argv() );
35 10 $self->opts( $cmd_line->get_result() );
36 }
37  
38 sub _get_output
39 {
40 8 ▶ my $self = shift;
Subroutine _get_output: called CC=2 SCAR=6.9
41 8 ▶ if ( $self->opts()->output_to_stdout() )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->opts->output_to_stdout) { } 7 1 8
42 {
43 7 return ();
44 }
45 else
46 {
47 1 return ( $self->opts()->output_filename() );
48 }
49 }
50  
51 sub _get_mode_callbacks
52 {
53 return {
54 10 ▶ 'regular' => "_mode_regular",
Subroutine _get_mode_callbacks: called CC=1 SCAR=0.0
55 'help' => "_mode_help",
56 'version' => "_mode_version",
57 };
58 }
59  
60 sub _mode_version
61 {
62 1 ▶ print <<"EOF";
Subroutine _mode_version: called CC=1 SCAR=0.0
63 This is TTML version $Template::Preprocessor::TTML::VERSION
64 TTML is a Command Line Preprocessor based on the Template Toolkit
65 (http://www.template-toolkit.org/)
66  
67 More information about TTML can be found at:
68  
69 http://search.cpan.org/dist/Template-Preprocessor-TTML/
70 EOF
71 }
72  
73 sub _get_help_text
74 {
75 1 ▶ return <<"EOF";
Subroutine _get_help_text: called CC=1 SCAR=0.0
76 ttml - A Template Toolkit Based Preprocessor
77 Usage: ttml [-o OUTPUTFILE] [OPTIONS] INPUTFILE
78  
79 Options:
80 -o OUTPUTFILE - Output to file instead of stdout.
81 -I PATH, --include=PATH - Append PATH to the include path
82 -DVAR=VALUE, --define=VAR=VALUE - Define a pre-defined variable.
83 --includefile=FILE - Include FILE at the top.
84  
85 -V, --version - display the version number.
86 -h, --help - display this help listing.
87 EOF
88 }
89  
90 sub _mode_help
91 {
92 1 ▶ my $self = shift;
Subroutine _mode_help: called CC=1 SCAR=0.0
93  
94 1 print $self->_get_help_text();
95  
96 1 return 0;
97 }
98  
99 sub run
100 {
101 10 ▶ my $self = shift;
Subroutine run: called CC=1 SCAR=0.0
Pod documented
102 10 $self->_calc_opts();
103  
104 return $self->can(
105 10 $self->_get_mode_callbacks()->{ $self->opts()->run_mode() } )->($self);
106 }
107  
108 sub _mode_regular
109 {
110 8 ▶ my $self = shift;
Subroutine _mode_regular: called CC=2 SCAR=6.9
111 my $config = {
112 8 INCLUDE_PATH => [ @{ $self->opts()->include_path() }, ".", ],
113 EVAL_PERL => 1,
114 PRE_PROCESS => $self->opts()->include_files(),
115 };
116 8 my $template = Template->new($config);
117  
118 8 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not $template->process($self->opts->input_filename, $self->opts->defines, $self->_get_output)) 1 7 8
119 !$template->process(
120 $self->opts()->input_filename(), $self->opts()->defines(),
121 $self->_get_output(),
122 )
123 )
124 {
125 1 die $template->error();
126 }
127 }
128  
129  
130 4 1;
131  
132 __END__
« Build ↑ Summary blib/lib/Template/Preprocessor/TTML/Base.pm »