| 1 | package Template::Plugin::ShellQuote; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use String::ShellQuote; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Template::Plugin::Filter; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use base qw(Template::Plugin::Filter); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use vars qw($VERSION $FILTER_NAME); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 1 | $VERSION = '1.3'; | |||||||||
| 10 | 1 | $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 <simon@thegestalt.org> | ||||||||||
| 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<String::ShellQuote>, L<Template::Plugin::Filter> | ||||||||||
| 62 | |||||||||||
| 63 | =cut | ||||||||||
| 64 | |||||||||||
| 65 | |||||||||||
| 66 | 1 | ▶ | sub init { | ||||||||
|
Subroutine
init: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 67 | 1 | my ($self,@args) = @_; | |||||||||
| 68 | 1 | ▶ | my $config = (ref $args[-1] eq 'HASH')? pop @args : {}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | |||||||||||
| 70 | |||||||||||
| 71 | 1 | $self->{_DYNAMIC} = 1; | |||||||||
| 72 | 1 | $self->install_filter($FILTER_NAME); | |||||||||
| 73 | |||||||||||
| 74 | 1 | return $self; | |||||||||
| 75 | |||||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | # possibly extraneous cargo culting but it works so ... | ||||||||||
| 79 | 11 | ▶ | sub filter { | ||||||||
|
Subroutine
filter: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||
| 80 | 11 | my ($self, $text, @args) = @_; | |||||||||
| 81 | 11 | ▶ | my $config = (ref $args[-1] eq 'HASH')? pop @args : {}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | |||||||||||
| 83 | 11 | ▶ | if ($config->{comment}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | 0 | return shell_comment_quote $text; | |||||||||
| 85 | } else { | ||||||||||
| 86 | 11 | return shell_quote $text; | |||||||||
| 87 | } | ||||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 1 | 1; | |||||||||
| 91 | |||||||||||