line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
=head1 NAME |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
Templer::Plugin::TimeStamp - A plugin to get TimeStamp of source files |
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
|
|
|
|
|
|
|
mtime: timestamp(%Y-%m-%d %H:M:%S) |
14
|
|
|
|
|
|
|
---- |
15
|
|
|
|
|
|
|
<p>This file has been last modified on <!-- tmpl_var name='mtime' -->. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 DESCRIPTION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
This plugin allows template variables to be set to the source file |
22
|
|
|
|
|
|
|
modification time. The parameter passed to the function are passed as is to |
23
|
|
|
|
|
|
|
strftime with leading and trailing spaces removed. |
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
|
|
|
11
|
|
3980
|
use strict; |
|
11
|
|
|
|
|
12
|
|
|
11
|
|
|
|
|
244
|
|
61
|
11
|
|
|
11
|
|
29
|
use warnings; |
|
11
|
|
|
|
|
11
|
|
|
11
|
|
|
|
|
229
|
|
62
|
|
|
|
|
|
|
|
63
|
11
|
|
|
11
|
|
29
|
use POSIX qw{strftime}; |
|
11
|
|
|
|
|
9
|
|
|
11
|
|
|
|
|
39
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
package Templer::Plugin::TimeStamp; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Constructor. No arguments are required/supported. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub new |
76
|
|
|
|
|
|
|
{ |
77
|
11
|
|
|
11
|
0
|
22
|
my ( $proto, %supplied ) = (@_); |
78
|
11
|
|
33
|
|
|
54
|
my $class = ref($proto) || $proto; |
79
|
|
|
|
|
|
|
|
80
|
11
|
|
|
|
|
14
|
my $self = {}; |
81
|
11
|
|
|
|
|
138
|
bless( $self, $class ); |
82
|
11
|
|
|
|
|
76
|
return $self; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 expand_variables |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
This is the method which is called by the L<Templer::Plugin::Factory> |
89
|
|
|
|
|
|
|
to expand the variables contained in a L<Templer::Site::Page> object. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Variables are written in the file in the form "key: value", and are |
92
|
|
|
|
|
|
|
internally stored within the Page object as a hash. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This method iterates over each key & value and updates any that |
95
|
|
|
|
|
|
|
seem to refer to timestamps. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub expand_variables |
100
|
|
|
|
|
|
|
{ |
101
|
9
|
|
|
9
|
1
|
14
|
my ( $self, $site, $page, $data ) = (@_); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
9
|
|
|
|
|
32
|
my %hash = %$data; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
9
|
|
|
|
|
13
|
my $mtime; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
9
|
|
|
|
|
24
|
foreach my $key ( keys %hash ) |
117
|
|
|
|
|
|
|
{ |
118
|
66
|
100
|
|
|
|
113
|
if ( $hash{ $key } =~ /^timestamp\((.*)\)/ ) |
119
|
|
|
|
|
|
|
{ |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
2
|
|
|
|
|
4
|
my $ts = $1; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
2
|
|
|
|
|
5
|
$ts =~ s/^\s+|\s+$//g; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
2
|
100
|
|
|
|
5
|
if ( !$mtime ) |
135
|
|
|
|
|
|
|
{ |
136
|
1
|
|
|
|
|
3
|
$mtime = ( stat( $page->source() ) )[9]; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
2
|
|
|
|
|
91
|
my @mtime = localtime($mtime); |
143
|
2
|
|
|
|
|
46
|
$hash{ $key } = POSIX::strftime $ts, @mtime; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
|
150
|
9
|
|
|
|
|
22
|
return ( \%hash ); |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Templer::Plugin::Factory->new()->register_plugin("Templer::Plugin::TimeStamp"); |
158
|
|
|
|
|
|
|
|