| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Copyright 2014-2016 - Giovanni Simoni |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# This file is part of PFT. |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# PFT is free software: you can redistribute it and/or modify it under the |
|
6
|
|
|
|
|
|
|
# terms of the GNU General Public License as published by the Free |
|
7
|
|
|
|
|
|
|
# Software Foundation, either version 3 of the License, or (at your |
|
8
|
|
|
|
|
|
|
# option) any later version. |
|
9
|
|
|
|
|
|
|
# |
|
10
|
|
|
|
|
|
|
# PFT is distributed in the hope that it will be useful, but WITHOUT ANY |
|
11
|
|
|
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12
|
|
|
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13
|
|
|
|
|
|
|
# for more details. |
|
14
|
|
|
|
|
|
|
# |
|
15
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License along |
|
16
|
|
|
|
|
|
|
# with PFT. If not, see . |
|
17
|
|
|
|
|
|
|
# |
|
18
|
|
|
|
|
|
|
package PFT::Header v1.4.1; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=encoding utf8 |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 NAME |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
PFT::Header - Header for PFT content textfiles |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use PFT::Header; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $hdr = PFT::Header->new( |
|
31
|
|
|
|
|
|
|
title => $title, # mandatory (conditions apply) |
|
32
|
|
|
|
|
|
|
slug => $slug, # optional short identifier |
|
33
|
|
|
|
|
|
|
date => $date, # optional (conditions apply) PFT::Date |
|
34
|
|
|
|
|
|
|
author => $author, # optional |
|
35
|
|
|
|
|
|
|
tags => $tags, # list of decoded strins, defaults to [] |
|
36
|
|
|
|
|
|
|
opts => $opts, # ignored by internals, defaults to {} |
|
37
|
|
|
|
|
|
|
); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $hdr = PFT::Header->load(\*STDIN); |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $hdr = PFT::Header->load('/path/to/file'); |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
A header is a chunk of meta-information describing content properties. |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
It is used in a PFT::Tree::Content structure as index for retrieving the |
|
48
|
|
|
|
|
|
|
content on the filesystem. Every textual content (i.e. |
|
49
|
|
|
|
|
|
|
PFT::Content::Entry) stores a textual representation of an header in the |
|
50
|
|
|
|
|
|
|
beginning of the file. |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 Structure |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Each content has a I, an optional I, an optional list of |
|
55
|
|
|
|
|
|
|
I in form of strings, an optional hash I containing other |
|
56
|
|
|
|
|
|
|
options. |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 Textual representation |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
The textual representation of a header starts with a valid YAML document |
|
61
|
|
|
|
|
|
|
(including the leading '---' line and ends with another '---' line). |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 Construction |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
The header can be constructed in three ways, corresponding to the three |
|
66
|
|
|
|
|
|
|
forms in the B. |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
The first form is constructed in code. The I field is mandatory |
|
69
|
|
|
|
|
|
|
unless there is a I field, and the date represents a month (i.e. |
|
70
|
|
|
|
|
|
|
lacks the I field). This property is enforced by the constructor. |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
The second and third forms are equivalent, and they differ in the source |
|
73
|
|
|
|
|
|
|
from which a header is loaded (a stream or a file path, respectively). |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
|
76
|
|
|
|
|
|
|
|
|
77
|
7
|
|
|
7
|
|
97864
|
use utf8; |
|
|
7
|
|
|
|
|
22
|
|
|
|
7
|
|
|
|
|
33
|
|
|
78
|
7
|
|
|
7
|
|
224
|
use v5.16; |
|
|
7
|
|
|
|
|
21
|
|
|
79
|
7
|
|
|
7
|
|
33
|
use strict; |
|
|
7
|
|
|
|
|
12
|
|
|
|
7
|
|
|
|
|
156
|
|
|
80
|
7
|
|
|
7
|
|
96
|
use warnings; |
|
|
7
|
|
|
|
|
14
|
|
|
|
7
|
|
|
|
|
227
|
|
|
81
|
|
|
|
|
|
|
|
|
82
|
7
|
|
|
7
|
|
39
|
use Carp; |
|
|
7
|
|
|
|
|
11
|
|
|
|
7
|
|
|
|
|
369
|
|
|
83
|
7
|
|
|
7
|
|
475
|
use Encode::Locale; |
|
|
7
|
|
|
|
|
3234
|
|
|
|
7
|
|
|
|
|
252
|
|
|
84
|
7
|
|
|
7
|
|
75
|
use Encode; |
|
|
7
|
|
|
|
|
13
|
|
|
|
7
|
|
|
|
|
478
|
|
|
85
|
7
|
|
|
7
|
|
3758
|
use YAML::Tiny; |
|
|
7
|
|
|
|
|
39410
|
|
|
|
7
|
|
|
|
|
419
|
|
|
86
|
|
|
|
|
|
|
|
|
87
|
7
|
|
|
7
|
|
2805
|
use PFT::Date; |
|
|
7
|
|
|
|
|
17
|
|
|
|
7
|
|
|
|
|
9869
|
|
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# Restrictions on header fields are handled by the following function, |
|
90
|
|
|
|
|
|
|
# as they are not just booleans. |
|
91
|
|
|
|
|
|
|
sub _params_check { |
|
92
|
217
|
|
|
217
|
|
346
|
my $params = shift; |
|
93
|
|
|
|
|
|
|
|
|
94
|
217
|
100
|
100
|
|
|
859
|
if (exists $params->{date} and defined(my $d = $params->{date})) { |
|
95
|
174
|
100
|
|
|
|
810
|
$d->isa('PFT::Date') |
|
96
|
|
|
|
|
|
|
or confess 'date parameter must be PFT::Date'; |
|
97
|
|
|
|
|
|
|
|
|
98
|
173
|
100
|
66
|
|
|
442
|
if ($d->complete) { |
|
|
|
100
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
$params->{title} |
|
100
|
162
|
100
|
|
|
|
553
|
or croak 'Title is mandatory headers having complete date'; |
|
101
|
|
|
|
|
|
|
} elsif (!defined $d->y or !defined $d->m) { |
|
102
|
1
|
|
|
|
|
96
|
croak 'Year and month are mandatory for headers with date'; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
} else { |
|
105
|
|
|
|
|
|
|
$params->{title} |
|
106
|
43
|
50
|
|
|
|
104
|
or croak 'Title is mandatory for headers not having dates'; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
}; |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# Keys are recognized options. Values are arrays: |
|
111
|
|
|
|
|
|
|
# - The default option; |
|
112
|
|
|
|
|
|
|
# - The normalization callback, or undef if the normalization is the |
|
113
|
|
|
|
|
|
|
# identity function. |
|
114
|
|
|
|
|
|
|
my %OPTS_RECIPE = ( |
|
115
|
|
|
|
|
|
|
hide => [0, sub { 0 + shift }], |
|
116
|
|
|
|
|
|
|
template => [undef, undef ], |
|
117
|
|
|
|
|
|
|
); |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub _opts_default { |
|
120
|
62
|
|
|
62
|
|
90
|
my %out; |
|
121
|
62
|
|
|
|
|
225
|
while (my($k, $vs) = each %OPTS_RECIPE) { |
|
122
|
124
|
|
|
|
|
415
|
$out{$k} = $vs->[0] |
|
123
|
|
|
|
|
|
|
} |
|
124
|
62
|
|
|
|
|
168
|
\%out |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub _opts_normalize { |
|
128
|
206
|
|
|
206
|
|
302
|
my $opts = shift; |
|
129
|
206
|
|
|
|
|
814
|
foreach (keys %$opts) { |
|
130
|
412
|
100
|
|
|
|
1035
|
if (defined(my $cb = $OPTS_RECIPE{$_}->[1])) { |
|
131
|
206
|
|
|
|
|
434
|
$opts->{$_} = $cb->($opts->{$_}) |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
$opts |
|
135
|
206
|
|
|
|
|
959
|
} |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub new { |
|
138
|
65
|
|
|
65
|
0
|
6673
|
my $cls = shift; |
|
139
|
65
|
|
|
|
|
217
|
my %params = @_; |
|
140
|
|
|
|
|
|
|
|
|
141
|
65
|
|
|
|
|
193
|
_params_check(\%params); |
|
142
|
|
|
|
|
|
|
bless { |
|
143
|
|
|
|
|
|
|
title => $params{title}, |
|
144
|
|
|
|
|
|
|
author => $params{author}, |
|
145
|
|
|
|
|
|
|
date => $params{date}, |
|
146
|
|
|
|
|
|
|
tags => $params{tags} || [], |
|
147
|
|
|
|
|
|
|
opts => $params{opts} || _opts_default(), |
|
148
|
62
|
|
100
|
|
|
365
|
slug => do { |
|
|
|
|
33
|
|
|
|
|
|
149
|
62
|
|
100
|
|
|
187
|
my $given = $params{slug} || $params{title}; |
|
150
|
62
|
100
|
|
|
|
185
|
defined $given ? slugify($given) : undef |
|
151
|
|
|
|
|
|
|
}, |
|
152
|
|
|
|
|
|
|
}, $cls; |
|
153
|
|
|
|
|
|
|
} |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub load { |
|
156
|
154
|
|
|
154
|
0
|
1724
|
my($cls, $from) = @_; |
|
157
|
|
|
|
|
|
|
|
|
158
|
154
|
|
|
|
|
199
|
my $fname; |
|
159
|
154
|
100
|
|
|
|
364
|
if (my $type = ref $from) { |
|
160
|
84
|
|
|
|
|
189
|
$fname = "?? $type ??"; |
|
161
|
84
|
50
|
66
|
|
|
389
|
unless ($type eq 'GLOB' || $type eq 'IO::File') { |
|
162
|
0
|
|
|
|
|
0
|
confess "Only supporting GLOB and IO::File. Got $type"; |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
} else { |
|
165
|
70
|
|
|
|
|
101
|
$fname = $from; |
|
166
|
70
|
50
|
|
|
|
338
|
$from = IO::File->new($from) or confess "Cannot open $from"; |
|
167
|
|
|
|
|
|
|
} |
|
168
|
154
|
50
|
|
|
|
8258
|
binmode $from, ':encoding(locale)' or confess "Binmode: $!"; |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
# Header starts with a valid YAML document (including the leading |
|
171
|
|
|
|
|
|
|
# /^---$/ string) and ends with another /^---$/ string. |
|
172
|
154
|
|
|
|
|
8898
|
my $text = <$from>; |
|
173
|
154
|
|
|
|
|
365
|
local $_; |
|
174
|
154
|
|
|
|
|
529
|
while (<$from>) { |
|
175
|
1401
|
100
|
|
|
|
2731
|
last if ($_ =~ /^---$/); |
|
176
|
1249
|
|
|
|
|
2374
|
$text .= $_; |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
|
|
179
|
154
|
|
50
|
|
|
227
|
my $hdr = eval { YAML::Tiny::Load($text || '') }; |
|
|
154
|
|
|
|
|
534
|
|
|
180
|
154
|
100
|
|
|
|
69723
|
$hdr or confess "File $fname has corrupt header"; |
|
181
|
|
|
|
|
|
|
|
|
182
|
152
|
|
|
|
|
216
|
my $date; |
|
183
|
152
|
100
|
|
|
|
363
|
$hdr->{Date} and $date = eval { |
|
184
|
|
|
|
|
|
|
PFT::Date->from_string($hdr->{Date}) |
|
185
|
125
|
|
|
|
|
634
|
}; |
|
186
|
152
|
50
|
|
|
|
318
|
croak $@ =~ s/ at .*$//rs if $@; |
|
187
|
152
|
|
|
|
|
322
|
delete $hdr->{Date}; |
|
188
|
|
|
|
|
|
|
|
|
189
|
152
|
|
|
|
|
271
|
my $title = delete $hdr->{Title}; |
|
190
|
|
|
|
|
|
|
my $self = { |
|
191
|
|
|
|
|
|
|
title => $title, |
|
192
|
|
|
|
|
|
|
slug => do { |
|
193
|
152
|
|
33
|
|
|
338
|
my $given = delete $hdr->{Slug} || $title; |
|
194
|
152
|
50
|
|
|
|
365
|
defined $given ? slugify($given) : undef |
|
195
|
|
|
|
|
|
|
}, |
|
196
|
|
|
|
|
|
|
author => delete $hdr->{Author}, |
|
197
|
|
|
|
|
|
|
tags => [ do { |
|
198
|
152
|
|
|
|
|
266
|
my $tags = delete $hdr->{Tags}; |
|
199
|
152
|
50
|
|
|
|
609
|
ref $tags eq 'ARRAY' ? @$tags |
|
|
|
100
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
: defined $tags ? $tags |
|
201
|
|
|
|
|
|
|
: () |
|
202
|
|
|
|
|
|
|
}], |
|
203
|
|
|
|
|
|
|
date => $date, |
|
204
|
152
|
|
|
|
|
228
|
opts => _opts_normalize(delete $hdr->{Options}), |
|
205
|
|
|
|
|
|
|
}; |
|
206
|
152
|
|
|
|
|
379
|
_params_check($self); |
|
207
|
|
|
|
|
|
|
|
|
208
|
152
|
|
|
|
|
394
|
foreach (keys %$hdr) { |
|
209
|
0
|
|
|
|
|
0
|
warn 'Unexpected key in header: ', $_; |
|
210
|
|
|
|
|
|
|
} |
|
211
|
152
|
|
|
|
|
225
|
foreach (keys %{$self->{opts}}) { |
|
|
152
|
|
|
|
|
391
|
|
|
212
|
|
|
|
|
|
|
warn 'Unexpected key in header: opts.', $_ |
|
213
|
304
|
50
|
|
|
|
637
|
unless exists $OPTS_RECIPE{$_} |
|
214
|
|
|
|
|
|
|
} |
|
215
|
|
|
|
|
|
|
|
|
216
|
152
|
|
|
|
|
2942
|
bless $self, $cls; |
|
217
|
|
|
|
|
|
|
} |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head2 Functions |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
The following functions are not associated with an instance. Call them as |
|
222
|
|
|
|
|
|
|
C |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=over |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=item slugify |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
Given a string, construct a I, that is a simplified version of such |
|
229
|
|
|
|
|
|
|
string. |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
(TODO: better describe it, also w.r.t. Unicode) |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=cut |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
sub slugify { |
|
236
|
223
|
|
|
223
|
1
|
349
|
my $out = shift; |
|
237
|
223
|
50
|
|
|
|
400
|
confess 'Slugify of nothing?' unless $out; |
|
238
|
|
|
|
|
|
|
|
|
239
|
223
|
|
|
|
|
1126
|
$out =~ s/[\W_]/-/g; |
|
240
|
223
|
|
|
|
|
729
|
$out =~ s/-+$//; |
|
241
|
223
|
|
|
|
|
367
|
$out =~ s/^-+//; |
|
242
|
223
|
|
|
|
|
354
|
$out =~ s/--+/-/g; |
|
243
|
223
|
|
|
|
|
1131
|
lc $out |
|
244
|
|
|
|
|
|
|
}; |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=back |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=head2 Properties |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
$hdr->title |
|
251
|
|
|
|
|
|
|
$hdr->author |
|
252
|
|
|
|
|
|
|
$hdr->template |
|
253
|
|
|
|
|
|
|
$hdr->tags |
|
254
|
|
|
|
|
|
|
$hdr->date |
|
255
|
|
|
|
|
|
|
$hdr->opts |
|
256
|
|
|
|
|
|
|
$hdr->slug |
|
257
|
|
|
|
|
|
|
$hdr->tags_slug |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=over |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=item title |
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
Returns the title of the content. |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
Outputs a in decoded string. |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=cut |
|
268
|
|
|
|
|
|
|
|
|
269
|
188
|
|
|
188
|
1
|
1012
|
sub title { shift->{title} } |
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=item author |
|
272
|
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
Returns the author of the content, or undef if there is no author. |
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
Outputs a in decoded string. |
|
276
|
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=cut |
|
278
|
|
|
|
|
|
|
|
|
279
|
54
|
|
|
54
|
1
|
177
|
sub author { shift->{author} } |
|
280
|
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=item tags |
|
282
|
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
A list of tags declared by the header. |
|
284
|
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
The tags are in a normal (i.e. not slugified) form. For a slugified |
|
286
|
|
|
|
|
|
|
version use the C method. |
|
287
|
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
=cut |
|
289
|
|
|
|
|
|
|
|
|
290
|
74
|
50
|
|
74
|
1
|
230
|
sub tags { wantarray ? @{shift->{tags}} : shift->{tags} } |
|
|
0
|
|
|
|
|
0
|
|
|
291
|
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
=item date |
|
293
|
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
The date declared by the heade, as PFT::Date object. |
|
295
|
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
=cut |
|
297
|
|
|
|
|
|
|
|
|
298
|
309
|
|
|
309
|
1
|
862
|
sub date { shift->{date} } |
|
299
|
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
=item opts |
|
301
|
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
A list of options for this content. |
|
303
|
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
=cut |
|
305
|
|
|
|
|
|
|
|
|
306
|
54
|
50
|
|
54
|
1
|
176
|
sub opts { shift->{opts} || {} } |
|
307
|
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
=item slug |
|
309
|
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
A slug of the title. |
|
311
|
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
=cut |
|
313
|
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
sub slug { |
|
315
|
123
|
|
|
123
|
1
|
242
|
my $self = shift; |
|
316
|
123
|
0
|
0
|
|
|
685
|
$self->{slug} || $self->{title} && slugify($self->{title}) || undef |
|
|
|
|
33
|
|
|
|
|
|
317
|
|
|
|
|
|
|
} |
|
318
|
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
=item tags_slug |
|
320
|
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
A list of tags as for the C method, but in slugified form. |
|
322
|
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
=cut |
|
324
|
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
sub tags_slug { |
|
326
|
19
|
50
|
|
19
|
1
|
26
|
map slugify($_) => @{shift->tags || []} |
|
|
19
|
|
|
|
|
33
|
|
|
327
|
|
|
|
|
|
|
} |
|
328
|
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
=back |
|
330
|
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
=head2 Methods |
|
332
|
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
=over |
|
334
|
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
=item set_date |
|
336
|
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
Setter for date. The parameter must be a PFT::Date object. |
|
338
|
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
=cut |
|
340
|
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
sub set_date { |
|
342
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
343
|
0
|
|
|
|
|
0
|
my $date = pop; |
|
344
|
|
|
|
|
|
|
|
|
345
|
0
|
0
|
|
|
|
0
|
$date->isa('PFT::Date') or confess 'Must be PFT::Date'; |
|
346
|
0
|
|
|
|
|
0
|
$self->{date} = $date; |
|
347
|
|
|
|
|
|
|
} |
|
348
|
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
=item dump |
|
350
|
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
Dump the header on a file. A GLOB or IO::File is expected as argument. |
|
352
|
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
=cut |
|
354
|
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
sub dump { |
|
356
|
54
|
|
|
54
|
1
|
1398
|
my $self = shift; |
|
357
|
54
|
|
|
|
|
77
|
my $to = shift; |
|
358
|
|
|
|
|
|
|
|
|
359
|
54
|
|
|
|
|
135
|
my $type = ref $to; |
|
360
|
54
|
50
|
66
|
|
|
255
|
if ($type ne 'GLOB' && $type ne 'IO::File') { |
|
361
|
0
|
0
|
|
|
|
0
|
confess "Only supporting GLOB and IO::File. Got ", |
|
362
|
|
|
|
|
|
|
$type ? $type : 'Scalar' |
|
363
|
|
|
|
|
|
|
} |
|
364
|
54
|
|
|
|
|
114
|
my $tags = $self->tags; |
|
365
|
54
|
50
|
|
1
|
|
567
|
binmode $to, ':encoding(locale)' or confess "Cannot binmode: $!"; |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
11
|
|
|
|
1
|
|
|
|
|
8
|
|
|
366
|
54
|
100
|
|
|
|
2861
|
print $to YAML::Tiny::Dump({ |
|
|
|
100
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
Title => $self->title, |
|
368
|
|
|
|
|
|
|
Slug => $self->slug, |
|
369
|
|
|
|
|
|
|
Author => $self->author, |
|
370
|
|
|
|
|
|
|
Tags => @$tags ? $tags : undef, |
|
371
|
|
|
|
|
|
|
Date => $self->date ? $self->date->repr('-') : undef, |
|
372
|
|
|
|
|
|
|
Options => _opts_normalize($self->opts), |
|
373
|
|
|
|
|
|
|
}), "---\n"; |
|
374
|
|
|
|
|
|
|
} |
|
375
|
|
|
|
|
|
|
|
|
376
|
|
|
|
|
|
|
=back |
|
377
|
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
=cut |
|
379
|
|
|
|
|
|
|
|
|
380
|
|
|
|
|
|
|
1; |