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