File Coverage

blib/lib/Template/Plugin/ShellQuote.pm
Criterion Covered Total %
statement 24 25 96.0
branch 3 6 50.0
condition n/a
subroutine 7 7 100.0
pod 0 2 0.0
total 34 40 85.0


line stmt bran cond sub pod time code
1             package Template::Plugin::ShellQuote;
2              
3 1     1   30430 use strict;
  1         3  
  1         39  
4 1     1   933 use String::ShellQuote;
  1         972  
  1         82  
5 1     1   1404 use Template::Plugin::Filter;
  1         8240  
  1         32  
6 1     1   9 use base qw(Template::Plugin::Filter);
  1         2  
  1         78  
7 1     1   5 use vars qw($VERSION $FILTER_NAME);
  1         2  
  1         258  
8              
9             $VERSION = '1.3';
10             $FILTER_NAME = 'shellquote';
11              
12              
13             =pod
14              
15             =head1 NAME
16              
17             Template::Plugin::ShellQuote - provides a Template Toolkit filter to shell quote text
18              
19             =head1 SYNOPSIS
20              
21             [% USE ShellQuote %]
22             #!/bin/sh
23             [% FILTER shellquote %]
24             all this text
25             & this text
26             also *this* text
27             will be quoted suitable for putting in a shell script
28             [% END %]
29              
30             # this will do what you expect
31             [% somevar FILTER shellquote %]
32              
33             # suitably quote stuff for a comment
34             ./some_command # Some comment [% somevar FILTER shellquote (comment => 1 ) %]
35              
36             =head1 DESCRIPTION
37              
38             Really quite easy. Basically just provides a simple filter
39             so that you can easily create shell scripts using the
40             Template Toolkit.
41              
42             =head1 AUTHOR
43              
44             Simon Wistow
45              
46             =head1 COPYING
47              
48             (c)opyright 2003, Simon Wistow
49              
50             Distributed under the same terms as Perl itself.
51              
52             This software is under no warranty whatsoever and will probably ruin your life,
53             kill your friends, burn down your house and bring about the apocalypse.
54              
55             =head1 BUGS
56              
57             None known.
58              
59             =head1 SEE ALSO
60              
61             L, L
62              
63             =cut
64              
65              
66             sub init {
67 1     1 0 96481 my ($self,@args) = @_;
68 1 50       6 my $config = (ref $args[-1] eq 'HASH')? pop @args : {};
69              
70              
71 1         8 $self->{_DYNAMIC} = 1;
72 1         9 $self->install_filter($FILTER_NAME);
73              
74 1         43 return $self;
75              
76             }
77              
78             # possibly extraneous cargo culting but it works so ...
79             sub filter {
80 11     11 0 2992 my ($self, $text, @args) = @_;
81 11 50       24 my $config = (ref $args[-1] eq 'HASH')? pop @args : {};
82            
83 11 50       20 if ($config->{comment}) {
84 0         0 return shell_comment_quote $text;
85             } else {
86 11         23 return shell_quote $text;
87             }
88             }
89              
90             1;
91