line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Contenticious::Content::Node::Directory; |
2
|
5
|
|
|
5
|
|
924
|
use Mojo::Base 'Contenticious::Content::Node'; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
27
|
|
3
|
|
|
|
|
|
|
|
4
|
5
|
|
|
5
|
|
2200
|
use Contenticious::Content::Node::File; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
65
|
|
5
|
5
|
|
|
5
|
|
204
|
use List::Util 'first'; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
286
|
|
6
|
5
|
|
|
5
|
|
27
|
use Carp; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
3548
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has children => sub { shift->build_children }; |
9
|
|
|
|
|
|
|
has meta => sub { shift->build_meta }; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub build_children { |
12
|
37
|
|
|
37
|
0
|
60
|
my $self = shift; |
13
|
|
|
|
|
|
|
|
14
|
37
|
|
|
|
|
98
|
my $dirname = $self->filename; |
15
|
37
|
|
|
|
|
157
|
my @children = (); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# sort and iterate directory entries |
18
|
37
|
|
|
|
|
337
|
$dirname =~ s/ /\\ /g; |
19
|
37
|
|
|
|
|
1955
|
foreach my $entry (sort glob("$dirname/*")) { |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# add content file node |
22
|
95
|
100
|
66
|
|
|
3067
|
if ($entry =~ /.md$/ and -f -r $entry) { |
|
|
100
|
|
|
|
|
|
23
|
60
|
|
|
|
|
277
|
my $node = Contenticious::Content::Node::File->new( |
24
|
|
|
|
|
|
|
filename => $entry, |
25
|
|
|
|
|
|
|
path_prefix => $self->path, |
26
|
|
|
|
|
|
|
); |
27
|
60
|
|
|
|
|
859
|
push @children, $node; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# add content directory node |
31
|
|
|
|
|
|
|
elsif (-d -r -x $entry) { |
32
|
30
|
|
|
|
|
124
|
my $node = Contenticious::Content::Node::Directory->new( |
33
|
|
|
|
|
|
|
filename => $entry, |
34
|
|
|
|
|
|
|
path_prefix => $self->path, |
35
|
|
|
|
|
|
|
); |
36
|
30
|
|
|
|
|
326
|
push @children, $node; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
37
|
|
|
|
|
259
|
return \@children; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub build_meta { |
44
|
32
|
|
|
32
|
0
|
61
|
my $self = shift; |
45
|
32
|
|
|
|
|
55
|
my %meta = (); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# does a 'meta' file exist? |
48
|
32
|
|
|
|
|
100
|
my $meta_fn = $self->filename . '/meta'; |
49
|
32
|
100
|
|
|
|
1037
|
if (-f -r $meta_fn) { |
|
|
100
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# open file for decoded reading |
52
|
14
|
50
|
|
|
|
530
|
open my $meta_fh, '<:encoding(UTF-8)', $meta_fn |
53
|
|
|
|
|
|
|
or croak "couldn't open $meta_fn: $!"; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# slurp |
56
|
14
|
|
|
|
|
977
|
my $meta_fc = do { local $/; <$meta_fh> }; |
|
14
|
|
|
|
|
63
|
|
|
14
|
|
|
|
|
339
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# extract meta information |
59
|
14
|
|
|
|
|
737
|
$meta{lc $1} = $2 |
60
|
|
|
|
|
|
|
while $meta_fc =~ s/\A(\w+):\s*(.*)[\n\r]+//; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# get meta information from 'index' node |
64
|
|
|
|
|
|
|
elsif (my $index = $self->find_child('index')) { |
65
|
14
|
|
|
|
|
28
|
$meta{$_} = $index->meta->{$_} for keys %{$index->meta}; |
|
14
|
|
|
|
|
48
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
32
|
|
|
|
|
894
|
return \%meta; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub build_html { |
72
|
9
|
|
|
9
|
0
|
19
|
my $self = shift; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# try to find index |
75
|
9
|
|
|
|
|
25
|
my $index = $self->find_child('index'); |
76
|
9
|
100
|
|
|
|
96
|
return unless $index; |
77
|
|
|
|
|
|
|
|
78
|
3
|
|
|
|
|
16
|
return $index->html; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub find_child { |
82
|
103
|
|
|
103
|
1
|
213
|
my ($self, $name) = @_; |
83
|
103
|
|
|
231
|
|
377
|
return first {$_->name eq $name} @{$self->children}; |
|
231
|
|
|
|
|
960
|
|
|
103
|
|
|
|
|
257
|
|
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub find { |
87
|
105
|
|
|
105
|
1
|
6408
|
my ($self, @names) = @_; |
88
|
105
|
|
|
|
|
151
|
my $node = $self; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# done |
91
|
105
|
100
|
|
|
|
267
|
return $node unless @names; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# find matching child node |
94
|
76
|
|
|
|
|
143
|
my $name = shift @names; |
95
|
76
|
|
|
|
|
189
|
$node = $self->find_child($name); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# couldn't find |
98
|
76
|
100
|
|
|
|
486
|
return unless $node; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# continue search on child node |
101
|
57
|
|
|
|
|
201
|
return $node->find(@names); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
__END__ |