| 1 | |||||||||||||||||||||
| 2 | =head1 NAME | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | Templer::Plugin::Strict - A XML-like strict syntax for templates tags. | ||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | =cut | ||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | =head1 DESCRIPTION | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | This class implements a layout template filter plugin for C<templer> which | ||||||||||||||||||||
| 11 | allows empty-element template tags to be written as in XML. | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | This allows the following syntax | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | =over | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | =item C<<TMPL_VAR NAME="PARAMETER_NAME"/>> | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | =item C<<TMPL_INCLUDE NAME="filename.tmpl"/>> | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | =item C<<TMPL_ELSE/>> | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | =back | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | =cut | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | =head1 LICENSE | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | This module is free software; you can redistribute it and/or modify it | ||||||||||||||||||||
| 30 | under the terms of either: | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | a) the GNU General Public License as published by the Free Software | ||||||||||||||||||||
| 33 | Foundation; either version 2, or (at your option) any later version, | ||||||||||||||||||||
| 34 | or | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | b) the Perl "Artistic License". | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | =cut | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | =head1 AUTHOR | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | Bruno Beaufils <bruno@boulgour.com> | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | =cut | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | Copyright (C) 2015 Bruno Beaufils <bruno@boulgour.com>. | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | This library is free software. You can modify and or distribute it under | ||||||||||||||||||||
| 51 | the same terms as Perl itself. | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | =cut | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | =head1 METHODS | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | =cut | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 11 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 61 | 11 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | package Templer::Plugin::Strict; | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | =head2 new | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | Constructor. No arguments are supported/expected. | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | =cut | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | sub new | ||||||||||||||||||||
| 74 | 3 | ▶ | { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||
| 75 | 3 | my ( $proto, %supplied ) = (@_); | |||||||||||||||||||
| 76 | 3 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 3 | my $self = {}; | |||||||||||||||||||
| 79 | 3 | bless( $self, $class ); | |||||||||||||||||||
| 80 | 3 | return $self; | |||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | =head2 available | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | This plugin is always available. | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | =cut | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | sub available | ||||||||||||||||||||
| 91 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
available: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 92 | 1 | return 1; | |||||||||||||||||||
| 93 | } | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | =head2 filter | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | Filter the given template. | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | =cut | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | sub filter | ||||||||||||||||||||
| 103 | 3 | ▶ | { | ||||||||||||||||||
|
Subroutine
filter: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 104 | 3 | my ( $self, $str ) = (@_); | |||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 3 | $str =~ s{\<tmpl_var([^>/]*)/\>}{<tmpl_var$1>}ig; | |||||||||||||||||||
| 107 | 3 | $str =~ s{\<tmpl_include([^>/]*)/\>}{<tmpl_include$1>}ig; | |||||||||||||||||||
| 108 | 3 | $str =~ s{\<tmpl_else/\>}{<tmpl_else>}ig; | |||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 3 | return $str; | |||||||||||||||||||
| 111 | } | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 11 | Templer::Plugin::Factory->new() | |||||||||||||||||||
| 114 | ->register_filter( "strict", "Templer::Plugin::Strict" ); | ||||||||||||||||||||