| 1 | #! /bin/false | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | # Copyright (C) 2016-2018 Guido Flohr <guido.flohr@cantanea.com>, | ||||||||||||||||||||||||||||||
| 4 | # all rights reserved. | ||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||
| 6 | # This program is free software: you can redistribute it and/or modify | ||||||||||||||||||||||||||||||
| 7 | # it under the terms of the GNU General Public License as published by | ||||||||||||||||||||||||||||||
| 8 | # the Free Software Foundation; either version 3 of the License, or | ||||||||||||||||||||||||||||||
| 9 | # (at your option) any later version. | ||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||
| 11 | # This program is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||||||||||||
| 14 | # GNU General Public License for more details. | ||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||
| 16 | # You should have received a copy of the GNU General Public License | ||||||||||||||||||||||||||||||
| 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||
| 19 | package Qgoda::Processor::TT2; | ||||||||||||||||||||||||||||||
| 20 | 2 | $Qgoda::Processor::TT2::VERSION = 'v0.9.2'; | |||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||
| 23 | 2 | ▶ | use Template; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use Locale::TextDomain qw(qgoda); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||
| 27 | 2 | ▶ | use Qgoda::Util qw(empty); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | use base qw(Qgoda::Processor); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||
| 31 | 2 | my %instances; | |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||
| 33 | sub new { | ||||||||||||||||||||||||||||||
| 34 | 2 | ▶ | my ($class, %options) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.6
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||
| 36 | 2 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||
| 37 | 2 | $self->{__options} = \%options; | |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||
| 39 | 2 | require Qgoda; | |||||||||||||||||||||||||||||
| 40 | 2 | my $qgoda = Qgoda->new; | |||||||||||||||||||||||||||||
| 41 | 2 | my $config = $qgoda->config; | |||||||||||||||||||||||||||||
| 42 | 2 | my $srcdir = $config->{srcdir}; | |||||||||||||||||||||||||||||
| 43 | 2 | my $viewdir = $config->{paths}->{views}; | |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||
| 45 | # FIXME! Merge options with those from the configuration! | ||||||||||||||||||||||||||||||
| 46 | 2 | my %options = ( | |||||||||||||||||||||||||||||
| 47 | INCLUDE_PATH => [File::Spec->join($srcdir, $viewdir)], | ||||||||||||||||||||||||||||||
| 48 | PLUGIN_BASE => ['Qgoda::TT2::Plugin'], | ||||||||||||||||||||||||||||||
| 49 | RECURSION => 1, | ||||||||||||||||||||||||||||||
| 50 | # Needed for qgoda po pot | ||||||||||||||||||||||||||||||
| 51 | RELATIVE => 1 | ||||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||||
| 53 | 2 | my $scm = $config->{scm}; | |||||||||||||||||||||||||||||
| 54 | 2 | ▶ | if (!empty $scm && 'git' eq $scm) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not &empty($scm) and "git" eq $scm
MC/DC0%0/2
not &empty($scm) and "git" eq $scm
not &empty($scm)
"git" eq $scm
Truth table33%1/3
not(A) and B
A= not &empty($scm)B= "git" eq $scm
| |||||||||||||||||||||||||||||||
| 55 | 0 | my $provider = Qgoda::Template::GitProvider->new(%options); | |||||||||||||||||||||||||||||
| 56 | 0 | $options{LOAD_TEMPLATES} = [$provider]; | |||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||
| 58 | 2 | ▶ | $self->{__tt} = Template->new({ | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 59 | %options | ||||||||||||||||||||||||||||||
| 60 | }) or die Template->error; | ||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||
| 62 | 2 | return $self; | |||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||
| 65 | sub process { | ||||||||||||||||||||||||||||||
| 66 | 6 | ▶ | my ($self, $content, $asset, $filename) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
process: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||
| 68 | 6 | require Qgoda; | |||||||||||||||||||||||||||||
| 69 | 6 | my $qgoda = Qgoda->new; | |||||||||||||||||||||||||||||
| 70 | 6 | my $srcdir = $qgoda->config->{srcdir}; | |||||||||||||||||||||||||||||
| 71 | 6 | my $viewdir = $qgoda->config->{paths}->{views}; | |||||||||||||||||||||||||||||
| 72 | 6 | my $absviewdir = File::Spec->rel2abs($viewdir, $srcdir); | |||||||||||||||||||||||||||||
| 73 | 6 | my $gettext_filename = File::Spec->abs2rel($filename, $absviewdir); | |||||||||||||||||||||||||||||
| 74 | 6 | my $vars = { | |||||||||||||||||||||||||||||
| 75 | asset => $asset, | ||||||||||||||||||||||||||||||
| 76 | config => Qgoda->new->config, | ||||||||||||||||||||||||||||||
| 77 | gettext_filename => $gettext_filename, | ||||||||||||||||||||||||||||||
| 78 | }; | ||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||
| 80 | 6 | my $cooked; | |||||||||||||||||||||||||||||
| 81 | $self->{__tt}->process(\$content, $vars, \$cooked) | ||||||||||||||||||||||||||||||
| 82 | 6 | ▶ | or die $self->{__tt}->error, "\n" if !defined $cooked; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%2/4
defined $cooked || ($self->{'__tt'}->process(\$content, $vars, \$cooked) || die($self->{'__tt'}->error, "\n"))
$self->{"__tt"}->process(\$content, $vars, \$cooked) or die $self->{"__tt"}->error, "\n"
MC/DC0%0/2
defined $cooked || ($self->{'__tt'}->process(\$content, $vars, \$cooked) || die($self->{'__tt'}->error, "\n"))
defined $cooked
$self->{"__tt"}->process(\$content, $vars, \$cooked)
Truth table33%1/3
A || B
A= defined $cookedB= $self->{"__tt"}->process(\$content, $vars, \$cooked)
| |||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||
| 84 | 6 | return $cooked; | |||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||
| 87 | package Qgoda::Template::GitProvider; | ||||||||||||||||||||||||||||||
| 88 | 2 | $Qgoda::Template::GitProvider::VERSION = 'v0.9.2'; | |||||||||||||||||||||||||||||
| 89 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||
| 91 | 2 | ▶ | use Template::Constants; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 92 | 2 | ▶ | use Locale::TextDomain qw(qgoda); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||
| 94 | 2 | ▶ | use base qw(Template::Provider); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||
| 96 | sub fetch { | ||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | my ($self, $name) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
fetch: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | if (!ref $name) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 100 | 0 | my $is_absolute; | |||||||||||||||||||||||||||||
| 101 | my $path; | ||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | if (File::Spec->file_name_is_absolute($name)) { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 104 | 0 | $is_absolute = 1; | |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | $path = $name if -e $name; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 106 | } elsif ($name !~ m/$Template::Provider::RELATIVE_PATH/o) { | ||||||||||||||||||||||||||||||
| 107 | 0 | foreach my $search (@{$self->{INCLUDE_PATH}}) { | |||||||||||||||||||||||||||||
| 108 | 0 | my $try = File::Spec->catfile($search, $name); | |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | if (-e $try) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 110 | 0 | $path = $try; | |||||||||||||||||||||||||||||
| 111 | 0 | $is_absolute = File::Spec->file_name_is_absolute($path); | |||||||||||||||||||||||||||||
| 112 | 0 | last; | |||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | if (defined $path | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $path and not "Qgoda"->new->versionControlled($path, $is_absolute)
MC/DC0%0/2
defined $path and not "Qgoda"->new->versionControlled($path, $is_absolute)
defined $path
not "Qgoda"->new->versionControlled($path, $is_absolute)
Truth table0%0/3
A and not(B)
A= defined $pathB= not "Qgoda"->new->versionControlled($path, $is_absolute)
| |||||||||||||||||||||||||||||||
| 118 | && !Qgoda->new->versionControlled($path, $is_absolute)) { | ||||||||||||||||||||||||||||||
| 119 | 0 | my $msg = __x("template file '{path}' is not under version control", | |||||||||||||||||||||||||||||
| 120 | path => $path); | ||||||||||||||||||||||||||||||
| 121 | 0 | return $msg, Template::Constants::STATUS_ERROR; | |||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||
| 125 | 0 | return $self->SUPER::fetch($name); | |||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||
| 128 | 2 | 1; | |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||
| 130 | =head1 NAME | ||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||
| 132 | Qgoda::Processor::TT2 - Qgoda Processor For the Template Toolkit Version 2 | ||||||||||||||||||||||||||||||