line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Contenticious::Content; |
2
|
4
|
|
|
4
|
|
824
|
use Mojo::Base -base; |
|
4
|
|
|
|
|
6584
|
|
|
4
|
|
|
|
|
23
|
|
3
|
|
|
|
|
|
|
|
4
|
4
|
|
|
4
|
|
1878
|
use Contenticious::Content::Node::Directory; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
32
|
|
5
|
4
|
|
|
4
|
|
2024
|
use File::Copy::Recursive 'dircopy'; |
|
4
|
|
|
|
|
10492
|
|
|
4
|
|
|
|
|
240
|
|
6
|
4
|
|
|
4
|
|
20
|
use Carp; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
1250
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has pages_dir => sub { croak 'no pages_dir given' }; |
9
|
|
|
|
|
|
|
has root_node => sub { shift->build_root_node }; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# root_node builder |
12
|
|
|
|
|
|
|
sub build_root_node { |
13
|
15
|
|
|
15
|
0
|
18
|
my $self = shift; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# let there be root! |
16
|
15
|
|
|
|
|
50
|
return Contenticious::Content::Node::Directory->new( |
17
|
|
|
|
|
|
|
filename => $self->pages_dir, |
18
|
|
|
|
|
|
|
is_root => 1, |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# find a content node for a given path like foo/bar/baz |
23
|
|
|
|
|
|
|
sub find { |
24
|
16
|
|
|
16
|
1
|
362
|
my $self = shift; |
25
|
16
|
|
100
|
|
|
47
|
my $path = shift // ''; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# split path and find content node |
28
|
16
|
|
|
|
|
50
|
my @names = split m|/| => $path; |
29
|
16
|
|
|
|
|
45
|
return $self->root_node->find(@names); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# execute a subroutine for all content nodes |
33
|
|
|
|
|
|
|
# the given subroutine gets the node as a single argument |
34
|
|
|
|
|
|
|
sub for_all_nodes { |
35
|
2
|
|
|
2
|
1
|
279
|
my ($self, $sub) = @_; |
36
|
2
|
|
|
|
|
8
|
_walk_tree($self->root_node, $sub); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# not a public method but a recursive utitlity function |
40
|
|
|
|
|
|
|
sub _walk_tree { |
41
|
14
|
|
|
14
|
|
66
|
my ($node, $sub) = @_; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# execute |
44
|
14
|
|
|
|
|
27
|
$sub->($node); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# walk the tree if possible (duck typing) |
47
|
14
|
100
|
|
|
|
115
|
if ($node->can('children')) { |
48
|
6
|
|
|
|
|
7
|
_walk_tree($_, $sub) foreach @{$node->children}; |
|
6
|
|
|
|
|
14
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# delete cached content |
53
|
|
|
|
|
|
|
sub empty_cache { |
54
|
12
|
|
|
12
|
1
|
67
|
my $self = shift; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# urgs |
57
|
12
|
|
|
|
|
126
|
delete $self->{root_node}; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
__END__ |