line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Contenticious::Content::Node::Directory; |
2
|
5
|
|
|
5
|
|
864
|
use Mojo::Base 'Contenticious::Content::Node'; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
23
|
|
3
|
|
|
|
|
|
|
|
4
|
5
|
|
|
5
|
|
1917
|
use Contenticious::Content::Node::File; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
65
|
|
5
|
5
|
|
|
5
|
|
136
|
use List::Util 'first'; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
265
|
|
6
|
5
|
|
|
5
|
|
21
|
use Carp; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
2801
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has children => sub { shift->build_children }; |
9
|
|
|
|
|
|
|
has meta => sub { shift->build_meta }; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub build_children { |
12
|
37
|
|
|
37
|
0
|
45
|
my $self = shift; |
13
|
|
|
|
|
|
|
|
14
|
37
|
|
|
|
|
83
|
my $dirname = $self->filename; |
15
|
37
|
|
|
|
|
135
|
my @children = (); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# sort and iterate directory entries |
18
|
37
|
|
|
|
|
88
|
$dirname =~ s/ /\\ /g; |
19
|
37
|
|
|
|
|
1511
|
foreach my $entry (sort glob("$dirname/*")) { |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# add content file node |
22
|
95
|
100
|
66
|
|
|
2433
|
if ($entry =~ /.md$/ and -f -r $entry) { |
|
|
100
|
|
|
|
|
|
23
|
60
|
|
|
|
|
170
|
my $node = Contenticious::Content::Node::File->new( |
24
|
|
|
|
|
|
|
filename => $entry, |
25
|
|
|
|
|
|
|
path_prefix => $self->path, |
26
|
|
|
|
|
|
|
); |
27
|
60
|
|
|
|
|
644
|
push @children, $node; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# add content directory node |
31
|
|
|
|
|
|
|
elsif (-d -r -x $entry) { |
32
|
30
|
|
|
|
|
74
|
my $node = Contenticious::Content::Node::Directory->new( |
33
|
|
|
|
|
|
|
filename => $entry, |
34
|
|
|
|
|
|
|
path_prefix => $self->path, |
35
|
|
|
|
|
|
|
); |
36
|
30
|
|
|
|
|
235
|
push @children, $node; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
37
|
|
|
|
|
211
|
return \@children; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub build_meta { |
44
|
32
|
|
|
32
|
0
|
36
|
my $self = shift; |
45
|
32
|
|
|
|
|
56
|
my %meta = (); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# does a 'meta' file exist? |
48
|
32
|
|
|
|
|
87
|
my $meta_fn = $self->filename . '/meta'; |
49
|
32
|
100
|
|
|
|
710
|
if (-f -r $meta_fn) { |
|
|
100
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# open file for decoded reading |
52
|
14
|
50
|
|
|
|
403
|
open my $meta_fh, '<:encoding(UTF-8)', $meta_fn |
53
|
|
|
|
|
|
|
or croak "couldn't open $meta_fn: $!"; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# slurp |
56
|
14
|
|
|
|
|
615
|
my $meta_fc = do { local $/; <$meta_fh> }; |
|
14
|
|
|
|
|
38
|
|
|
14
|
|
|
|
|
204
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# extract meta information |
59
|
14
|
|
|
|
|
530
|
$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
|
|
|
|
|
21
|
$meta{$_} = $index->meta->{$_} for keys %{$index->meta}; |
|
14
|
|
|
|
|
39
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
32
|
|
|
|
|
477
|
return \%meta; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub build_html { |
72
|
9
|
|
|
9
|
0
|
14
|
my $self = shift; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# try to find index |
75
|
9
|
|
|
|
|
15
|
my $index = $self->find_child('index'); |
76
|
9
|
100
|
|
|
|
71
|
return unless $index; |
77
|
|
|
|
|
|
|
|
78
|
3
|
|
|
|
|
14
|
return $index->html; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub find_child { |
82
|
103
|
|
|
103
|
1
|
121
|
my ($self, $name) = @_; |
83
|
103
|
|
|
231
|
|
260
|
return first {$_->name eq $name} @{$self->children}; |
|
231
|
|
|
|
|
782
|
|
|
103
|
|
|
|
|
182
|
|
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub find { |
87
|
105
|
|
|
105
|
1
|
3983
|
my ($self, @names) = @_; |
88
|
105
|
|
|
|
|
96
|
my $node = $self; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# done |
91
|
105
|
100
|
|
|
|
229
|
return $node unless @names; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# find matching child node |
94
|
76
|
|
|
|
|
83
|
my $name = shift @names; |
95
|
76
|
|
|
|
|
133
|
$node = $self->find_child($name); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# couldn't find |
98
|
76
|
100
|
|
|
|
384
|
return unless $node; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# continue search on child node |
101
|
57
|
|
|
|
|
181
|
return $node->find(@names); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
__END__ |