| 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(qw( | |||||||||
| 12 | argv | ||||||||||
| 13 | opts | ||||||||||
| 14 | )); | ||||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | 4 | our $VERSION = '0.0103'; | |||||||||
| 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 = Template::Preprocessor::TTML::CmdLineProc->new(argv => $self->argv()); | |||||||||
| 34 | 10 | $self->opts($cmd_line->get_result()); | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | sub _get_output | ||||||||||
| 38 | { | ||||||||||
| 39 | 8 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_get_output: called CC=2 SCAR=6.9
| |||||||||||
| 40 | 8 | ▶ | if ($self->opts()->output_to_stdout()) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | { | ||||||||||
| 42 | 7 | return (); | |||||||||
| 43 | } | ||||||||||
| 44 | else | ||||||||||
| 45 | { | ||||||||||
| 46 | 1 | return ($self->opts()->output_filename()); | |||||||||
| 47 | } | ||||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | sub _get_mode_callbacks | ||||||||||
| 51 | { | ||||||||||
| 52 | return { | ||||||||||
| 53 | 10 | ▶ | 'regular' => "_mode_regular", | ||||||||
|
Subroutine
_get_mode_callbacks: called CC=1 SCAR=0.0
| |||||||||||
| 54 | 'help' => "_mode_help", | ||||||||||
| 55 | 'version' => "_mode_version", | ||||||||||
| 56 | }; | ||||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | sub _mode_version | ||||||||||
| 60 | { | ||||||||||
| 61 | 1 | ▶ | print <<"EOF"; | ||||||||
|
Subroutine
_mode_version: called CC=1 SCAR=0.0
| |||||||||||
| 62 | This is TTML version $VERSION | ||||||||||
| 63 | TTML is a Command Line Preprocessor based on the Template Toolkit | ||||||||||
| 64 | (http://www.template-toolkit.org/) | ||||||||||
| 65 | |||||||||||
| 66 | More information about TTML can be found at: | ||||||||||
| 67 | |||||||||||
| 68 | http://search.cpan.org/dist/Template-Preprocessor-TTML/ | ||||||||||
| 69 | EOF | ||||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | sub _get_help_text | ||||||||||
| 73 | { | ||||||||||
| 74 | 1 | ▶ | return <<"EOF"; | ||||||||
|
Subroutine
_get_help_text: called CC=1 SCAR=0.0
| |||||||||||
| 75 | ttml - A Template Toolkit Based Preprocessor | ||||||||||
| 76 | Usage: ttml [-o OUTPUTFILE] [OPTIONS] INPUTFILE | ||||||||||
| 77 | |||||||||||
| 78 | Options: | ||||||||||
| 79 | -o OUTPUTFILE - Output to file instead of stdout. | ||||||||||
| 80 | -I PATH, --include=PATH - Append PATH to the include path | ||||||||||
| 81 | -DVAR=VALUE, --define=VAR=VALUE - Define a pre-defined variable. | ||||||||||
| 82 | --includefile=FILE - Include FILE at the top. | ||||||||||
| 83 | |||||||||||
| 84 | -V, --version - display the version number. | ||||||||||
| 85 | -h, --help - display this help listing. | ||||||||||
| 86 | EOF | ||||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | sub _mode_help | ||||||||||
| 90 | { | ||||||||||
| 91 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_mode_help: called CC=1 SCAR=0.0
| |||||||||||
| 92 | |||||||||||
| 93 | 1 | print $self->_get_help_text(); | |||||||||
| 94 | |||||||||||
| 95 | 1 | return 0; | |||||||||
| 96 | } | ||||||||||
| 97 | |||||||||||
| 98 | sub run | ||||||||||
| 99 | { | ||||||||||
| 100 | 10 | ▶ | my $self = shift; | ||||||||
|
Subroutine
run: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 101 | 10 | $self->_calc_opts(); | |||||||||
| 102 | |||||||||||
| 103 | return $self->can( | ||||||||||
| 104 | 10 | $self->_get_mode_callbacks()->{$self->opts()->run_mode()} | |||||||||
| 105 | )->($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 | { | ||||||||||
| 113 | 8 | INCLUDE_PATH => [ @{$self->opts()->include_path()}, ".", ], | |||||||||
| 114 | EVAL_PERL => 1, | ||||||||||
| 115 | PRE_PROCESS => $self->opts()->include_files(), | ||||||||||
| 116 | }; | ||||||||||
| 117 | 8 | my $template = Template->new($config); | |||||||||
| 118 | |||||||||||
| 119 | 8 | ▶ | if (! | ||||||||
|
Branch: 1 branch
| |||||||||||
| 120 | $template->process( | ||||||||||
| 121 | $self->opts()->input_filename(), | ||||||||||
| 122 | $self->opts()->defines(), | ||||||||||
| 123 | $self->_get_output(), | ||||||||||
| 124 | ) | ||||||||||
| 125 | ) | ||||||||||
| 126 | { | ||||||||||
| 127 | 1 | die $template->error(); | |||||||||
| 128 | } | ||||||||||
| 129 | } | ||||||||||
| 130 | |||||||||||
| 131 | |||||||||||
| 132 | 4 | 1; | |||||||||
| 133 | |||||||||||
| 134 | __END__ | ||||||||||