line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
=head1 NAME |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
Templer::Plugin::ShellCommand - A plugin to execute commands. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=cut |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 SYNOPSIS |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
The following is a good example use of this plugin |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
title: About my site |
13
|
|
|
|
|
|
|
hostname: run_command( hostname ) |
14
|
|
|
|
|
|
|
uptime: run_command( uptime ) |
15
|
|
|
|
|
|
|
---- |
16
|
|
|
|
|
|
|
<p>This is <!-- tmpl_var name='hostname' -->, with uptime of |
17
|
|
|
|
|
|
|
<!-- tmpl_var name='uptime' -->.</p> |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
This plugin allows template variables to be set to the output of |
24
|
|
|
|
|
|
|
executing shell-commands. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 LICENSE |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it |
31
|
|
|
|
|
|
|
under the terms of either: |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
a) the GNU General Public License as published by the Free Software |
34
|
|
|
|
|
|
|
Foundation; either version 2, or (at your option) any later version, |
35
|
|
|
|
|
|
|
or |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
b) the Perl "Artistic License". |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 AUTHOR |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Steve Kemp <steve@steve.org.uk> |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Copyright (C) 2012-2015 Steve Kemp <steve@steve.org.uk>. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
This library is free software. You can modify and or distribute it under |
52
|
|
|
|
|
|
|
the same terms as Perl itself. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 METHODS |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
11
|
|
|
11
|
|
3984
|
use strict; |
|
11
|
|
|
|
|
12
|
|
|
11
|
|
|
|
|
241
|
|
62
|
11
|
|
|
11
|
|
29
|
use warnings; |
|
11
|
|
|
|
|
25
|
|
|
11
|
|
|
|
|
1870
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
package Templer::Plugin::ShellCommand; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Constructor. No arguments are required/supported. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=cut |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub new |
75
|
|
|
|
|
|
|
{ |
76
|
11
|
|
|
11
|
0
|
18
|
my ( $proto, %supplied ) = (@_); |
77
|
11
|
|
33
|
|
|
55
|
my $class = ref($proto) || $proto; |
78
|
|
|
|
|
|
|
|
79
|
11
|
|
|
|
|
19
|
my $self = {}; |
80
|
11
|
|
|
|
|
13
|
bless( $self, $class ); |
81
|
11
|
|
|
|
|
76
|
return $self; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 expand_variables |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This is the method which is called by the L<Templer::Plugin::Factory> |
88
|
|
|
|
|
|
|
to expand the variables contained in a L<Templer::Site::Page> object. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Variables are written in the file in the form "key: value", and are |
91
|
|
|
|
|
|
|
internally stored within the Page object as a hash. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This method iterates over each key & value and updates any that |
94
|
|
|
|
|
|
|
seem to refer to shell commands. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub expand_variables |
99
|
|
|
|
|
|
|
{ |
100
|
9
|
|
|
9
|
1
|
12
|
my ( $self, $site, $page, $data ) = (@_); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
9
|
|
|
|
|
33
|
my %hash = %$data; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
9
|
|
|
|
|
29
|
foreach my $key ( keys %hash ) |
111
|
|
|
|
|
|
|
{ |
112
|
66
|
100
|
|
|
|
118
|
if ( $hash{ $key } =~ /^run_command\((.*)\)/ ) |
113
|
|
|
|
|
|
|
{ |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
1
|
|
|
|
|
2
|
my $cmd = $1; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
1
|
|
|
|
|
5
|
$cmd =~ s/^\s+|\s+$//g; |
124
|
|
|
|
|
|
|
|
125
|
1
|
|
|
|
|
2574
|
$hash{ $key } = `$cmd`; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
9
|
|
|
|
|
32
|
return ( \%hash ); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Templer::Plugin::Factory->new() |
141
|
|
|
|
|
|
|
->register_plugin("Templer::Plugin::ShellCommand"); |
142
|
|
|
|
|
|
|
|