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.3.0; |
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
|
|
100261
|
use utf8; |
|
7
|
|
|
|
|
22
|
|
|
7
|
|
|
|
|
36
|
|
78
|
7
|
|
|
7
|
|
226
|
use v5.16; |
|
7
|
|
|
|
|
23
|
|
79
|
7
|
|
|
7
|
|
34
|
use strict; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
140
|
|
80
|
7
|
|
|
7
|
|
93
|
use warnings; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
230
|
|
81
|
|
|
|
|
|
|
|
82
|
7
|
|
|
7
|
|
38
|
use Carp; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
415
|
|
83
|
7
|
|
|
7
|
|
484
|
use Encode::Locale; |
|
7
|
|
|
|
|
3351
|
|
|
7
|
|
|
|
|
272
|
|
84
|
7
|
|
|
7
|
|
71
|
use Encode; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
516
|
|
85
|
7
|
|
|
7
|
|
3874
|
use YAML::Tiny; |
|
7
|
|
|
|
|
40535
|
|
|
7
|
|
|
|
|
464
|
|
86
|
|
|
|
|
|
|
|
87
|
7
|
|
|
7
|
|
3519
|
use PFT::Date; |
|
7
|
|
|
|
|
20
|
|
|
7
|
|
|
|
|
10072
|
|
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
|
|
342
|
my $params = shift; |
93
|
|
|
|
|
|
|
|
94
|
217
|
100
|
100
|
|
|
983
|
if (exists $params->{date} and defined(my $d = $params->{date})) { |
95
|
174
|
100
|
|
|
|
1020
|
$d->isa('PFT::Date') |
96
|
|
|
|
|
|
|
or confess 'date parameter must be PFT::Date'; |
97
|
|
|
|
|
|
|
|
98
|
173
|
100
|
66
|
|
|
496
|
if ($d->complete) { |
|
|
100
|
|
|
|
|
|
99
|
|
|
|
|
|
|
$params->{title} |
100
|
162
|
100
|
|
|
|
626
|
or croak 'Title is mandatory headers having complete date'; |
101
|
|
|
|
|
|
|
} elsif (!defined $d->y or !defined $d->m) { |
102
|
1
|
|
|
|
|
93
|
croak 'Year and month are mandatory for headers with date'; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} else { |
105
|
|
|
|
|
|
|
$params->{title} |
106
|
43
|
50
|
|
|
|
117
|
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
|
|
103
|
my %out; |
121
|
62
|
|
|
|
|
228
|
while (my($k, $vs) = each %OPTS_RECIPE) { |
122
|
124
|
|
|
|
|
438
|
$out{$k} = $vs->[0] |
123
|
|
|
|
|
|
|
} |
124
|
62
|
|
|
|
|
174
|
\%out |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub _opts_normalize { |
128
|
206
|
|
|
206
|
|
356
|
my $opts = shift; |
129
|
206
|
|
|
|
|
861
|
foreach (keys %$opts) { |
130
|
412
|
100
|
|
|
|
1193
|
if (defined(my $cb = $OPTS_RECIPE{$_}->[1])) { |
131
|
206
|
|
|
|
|
453
|
$opts->{$_} = $cb->($opts->{$_}) |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
$opts |
135
|
206
|
|
|
|
|
1098
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub new { |
138
|
65
|
|
|
65
|
0
|
7056
|
my $cls = shift; |
139
|
65
|
|
|
|
|
245
|
my %params = @_; |
140
|
|
|
|
|
|
|
|
141
|
65
|
|
|
|
|
205
|
_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
|
|
|
416
|
slug => do { |
|
|
|
33
|
|
|
|
|
149
|
62
|
|
100
|
|
|
192
|
my $given = $params{slug} || $params{title}; |
150
|
62
|
100
|
|
|
|
213
|
defined $given ? slugify($given) : undef |
151
|
|
|
|
|
|
|
}, |
152
|
|
|
|
|
|
|
}, $cls; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub load { |
156
|
154
|
|
|
154
|
0
|
1874
|
my($cls, $from) = @_; |
157
|
|
|
|
|
|
|
|
158
|
154
|
|
|
|
|
228
|
my $fname; |
159
|
154
|
100
|
|
|
|
417
|
if (my $type = ref $from) { |
160
|
84
|
|
|
|
|
201
|
$fname = "?? $type ??"; |
161
|
84
|
50
|
66
|
|
|
364
|
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
|
|
|
|
|
130
|
$fname = $from; |
166
|
70
|
50
|
|
|
|
490
|
$from = IO::File->new($from) or confess "Cannot open $from"; |
167
|
|
|
|
|
|
|
} |
168
|
154
|
50
|
|
|
|
11233
|
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
|
|
|
|
|
10411
|
my $text = <$from>; |
173
|
154
|
|
|
|
|
408
|
local $_; |
174
|
154
|
|
|
|
|
575
|
while (<$from>) { |
175
|
1401
|
100
|
|
|
|
2816
|
last if ($_ =~ /^---$/); |
176
|
1249
|
|
|
|
|
2516
|
$text .= $_; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
154
|
|
50
|
|
|
261
|
my $hdr = eval { YAML::Tiny::Load($text || '') }; |
|
154
|
|
|
|
|
638
|
|
180
|
154
|
100
|
|
|
|
73167
|
$hdr or confess "File $fname has corrupt header"; |
181
|
|
|
|
|
|
|
|
182
|
152
|
|
|
|
|
243
|
my $date; |
183
|
152
|
100
|
|
|
|
397
|
$hdr->{Date} and $date = eval { |
184
|
|
|
|
|
|
|
PFT::Date->from_string($hdr->{Date}) |
185
|
125
|
|
|
|
|
817
|
}; |
186
|
152
|
50
|
|
|
|
344
|
croak $@ =~ s/ at .*$//rs if $@; |
187
|
152
|
|
|
|
|
373
|
delete $hdr->{Date}; |
188
|
|
|
|
|
|
|
|
189
|
152
|
|
|
|
|
297
|
my $title = delete $hdr->{Title}; |
190
|
|
|
|
|
|
|
my $self = { |
191
|
|
|
|
|
|
|
title => $title, |
192
|
|
|
|
|
|
|
slug => do { |
193
|
152
|
|
33
|
|
|
384
|
my $given = delete $hdr->{Slug} || $title; |
194
|
152
|
50
|
|
|
|
420
|
defined $given ? slugify($given) : undef |
195
|
|
|
|
|
|
|
}, |
196
|
|
|
|
|
|
|
author => delete $hdr->{Author}, |
197
|
|
|
|
|
|
|
tags => [ do { |
198
|
152
|
|
|
|
|
317
|
my $tags = delete $hdr->{Tags}; |
199
|
152
|
50
|
|
|
|
788
|
ref $tags eq 'ARRAY' ? @$tags |
|
|
100
|
|
|
|
|
|
200
|
|
|
|
|
|
|
: defined $tags ? $tags |
201
|
|
|
|
|
|
|
: () |
202
|
|
|
|
|
|
|
}], |
203
|
|
|
|
|
|
|
date => $date, |
204
|
152
|
|
|
|
|
261
|
opts => _opts_normalize(delete $hdr->{Options}), |
205
|
|
|
|
|
|
|
}; |
206
|
152
|
|
|
|
|
426
|
_params_check($self); |
207
|
|
|
|
|
|
|
|
208
|
152
|
|
|
|
|
451
|
foreach (keys %$hdr) { |
209
|
0
|
|
|
|
|
0
|
warn 'Unexpected key in header: ', $_; |
210
|
|
|
|
|
|
|
} |
211
|
152
|
|
|
|
|
219
|
foreach (keys %{$self->{opts}}) { |
|
152
|
|
|
|
|
416
|
|
212
|
|
|
|
|
|
|
warn 'Unexpected key in header: opts.', $_ |
213
|
304
|
50
|
|
|
|
754
|
unless exists $OPTS_RECIPE{$_} |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
152
|
|
|
|
|
3309
|
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
|
466
|
my $out = shift; |
237
|
223
|
50
|
|
|
|
476
|
confess 'Slugify of nothing?' unless $out; |
238
|
|
|
|
|
|
|
|
239
|
223
|
|
|
|
|
1365
|
$out =~ s/[\W_]/-/g; |
240
|
223
|
|
|
|
|
815
|
$out =~ s/-+$//; |
241
|
223
|
|
|
|
|
447
|
$out =~ s/^-+//; |
242
|
223
|
|
|
|
|
432
|
$out =~ s/--+/-/g; |
243
|
223
|
|
|
|
|
1698
|
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
|
1169
|
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
|
198
|
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
|
250
|
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
|
940
|
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
|
202
|
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
|
251
|
my $self = shift; |
316
|
123
|
0
|
0
|
|
|
675
|
$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
|
25
|
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
|
1534
|
my $self = shift; |
357
|
54
|
|
|
|
|
98
|
my $to = shift; |
358
|
|
|
|
|
|
|
|
359
|
54
|
|
|
|
|
108
|
my $type = ref $to; |
360
|
54
|
50
|
66
|
|
|
271
|
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
|
|
|
|
|
134
|
my $tags = $self->tags; |
365
|
54
|
50
|
|
1
|
|
624
|
binmode $to, ':encoding(locale)' or confess "Cannot binmode: $!"; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
366
|
54
|
100
|
|
|
|
3105
|
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; |