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
|
|
|
|
|
|
|
This file has been last modified on . |
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 |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Copyright (C) 2015 Bruno BEAUFILS . |
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
|
|
5113
|
use strict; |
|
11
|
|
|
|
|
23
|
|
|
11
|
|
|
|
|
288
|
|
61
|
11
|
|
|
11
|
|
43
|
use warnings; |
|
11
|
|
|
|
|
20
|
|
|
11
|
|
|
|
|
265
|
|
62
|
|
|
|
|
|
|
|
63
|
11
|
|
|
11
|
|
52
|
use POSIX qw{strftime}; |
|
11
|
|
|
|
|
216
|
|
|
11
|
|
|
|
|
70
|
|
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
|
28
|
my ( $proto, %supplied ) = (@_); |
78
|
11
|
|
33
|
|
|
115
|
my $class = ref($proto) || $proto; |
79
|
|
|
|
|
|
|
|
80
|
11
|
|
|
|
|
24
|
my $self = {}; |
81
|
11
|
|
|
|
|
22
|
bless( $self, $class ); |
82
|
11
|
|
|
|
|
93
|
return $self; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 expand_variables |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
This is the method which is called by the L |
89
|
|
|
|
|
|
|
to expand the variables contained in a L 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
|
29
|
my ( $self, $site, $page, $data ) = (@_); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# |
104
|
|
|
|
|
|
|
# Get the page-variables in the template. |
105
|
|
|
|
|
|
|
# |
106
|
9
|
|
|
|
|
53
|
my %hash = %$data; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# |
109
|
|
|
|
|
|
|
# The mtime of the page-source. Cached. |
110
|
|
|
|
|
|
|
# |
111
|
9
|
|
|
|
|
21
|
my $mtime; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# |
114
|
|
|
|
|
|
|
# Look for a value of "timestamp" in each key. |
115
|
|
|
|
|
|
|
# |
116
|
9
|
|
|
|
|
42
|
foreach my $key ( keys %hash ) |
117
|
|
|
|
|
|
|
{ |
118
|
66
|
100
|
|
|
|
174
|
if ( $hash{ $key } =~ /^timestamp\((.*)\)/ ) |
119
|
|
|
|
|
|
|
{ |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# |
122
|
|
|
|
|
|
|
# The format to use. |
123
|
|
|
|
|
|
|
# |
124
|
2
|
|
|
|
|
4
|
my $ts = $1; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# |
127
|
|
|
|
|
|
|
# Strip leading/trailing whitespace. |
128
|
|
|
|
|
|
|
# |
129
|
2
|
|
|
|
|
6
|
$ts =~ s/^\s+|\s+$//g; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# |
132
|
|
|
|
|
|
|
# Get mtime of the source file - if we've not already done so. |
133
|
|
|
|
|
|
|
# |
134
|
2
|
100
|
|
|
|
5
|
if ( !$mtime ) |
135
|
|
|
|
|
|
|
{ |
136
|
1
|
|
|
|
|
3
|
$mtime = ( stat( $page->source() ) )[9]; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# |
140
|
|
|
|
|
|
|
# Store formatted modification time |
141
|
|
|
|
|
|
|
# |
142
|
2
|
|
|
|
|
63
|
my @mtime = localtime($mtime); |
143
|
2
|
|
|
|
|
55
|
$hash{ $key } = POSIX::strftime $ts, @mtime; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
# |
148
|
|
|
|
|
|
|
# Return. |
149
|
|
|
|
|
|
|
# |
150
|
9
|
|
|
|
|
35
|
return ( \%hash ); |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# |
155
|
|
|
|
|
|
|
# Register the plugin. |
156
|
|
|
|
|
|
|
# |
157
|
|
|
|
|
|
|
Templer::Plugin::Factory->new()->register_plugin("Templer::Plugin::TimeStamp"); |