line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Contenticious::Commands; |
2
|
1
|
|
|
1
|
|
512
|
use Mojo::Base -base; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
133
|
use File::Copy::Recursive 'dircopy'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
5
|
1
|
|
|
1
|
|
3
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
329
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has app => sub { croak 'no app given' }; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub dump { |
10
|
1
|
|
|
1
|
1
|
152
|
my $self = shift; |
11
|
1
|
|
|
|
|
4
|
my $app = $self->app; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# prepare directory |
14
|
1
|
|
|
|
|
8
|
my $dd = $app->config->{dump_dir}; |
15
|
1
|
|
33
|
|
|
11
|
$dd //= $app->home->rel_dir('dump'); |
16
|
|
|
|
|
|
|
|
17
|
1
|
50
|
|
|
|
99
|
mkdir $dd unless -d $dd; |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
|
|
31
|
say 'dumping everything to ' . $dd . ' ...'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# copy static directory contents |
22
|
1
|
|
|
|
|
7
|
dircopy($_, $dd) for @{$app->static->paths}; |
|
1
|
|
|
|
|
5
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# silence! |
25
|
1
|
|
|
|
|
813
|
$app->log->level('warn'); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# pretty subdispatching |
28
|
1
|
|
|
|
|
48
|
$app->plugin('Subdispatch', {base_url => 'http://dummy_base'}); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# dump content |
31
|
|
|
|
|
|
|
$app->content->for_all_nodes(sub { |
32
|
7
|
|
|
7
|
|
6
|
my $node = shift; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# skip all index nodes (content from parent node) |
35
|
7
|
100
|
|
|
|
19
|
return if $node->name eq 'index'; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# determine dump file path |
38
|
6
|
100
|
|
|
|
42
|
my $path = $node->is_root ? 'index' : $node->path; |
39
|
6
|
|
|
|
|
33
|
my $df = "$dd/$path.html"; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# log 1 |
42
|
6
|
|
|
|
|
40
|
print "$path.html ... "; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# create directory if needed |
45
|
|
|
|
|
|
|
mkdir "$dd/$path" |
46
|
|
|
|
|
|
|
if not $node->is_root |
47
|
6
|
100
|
100
|
|
|
15
|
and $node->can('children') and @{$node->children} |
|
2
|
|
100
|
|
|
19
|
|
|
|
|
66
|
|
|
|
|
48
|
|
|
|
|
|
|
and not -d "$dd/$path"; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# get content |
51
|
6
|
|
|
|
|
153
|
my $res = $app->subdispatch->get('content', cpath => $node->path); |
52
|
6
|
|
|
|
|
552
|
my $html = $res->body; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# dump to file |
55
|
6
|
50
|
|
|
|
507
|
open my $fh, '>', $df or die "couldn't open file $df: $!"; |
56
|
6
|
|
|
|
|
43
|
print $fh $html; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# log 2 |
59
|
6
|
|
|
|
|
384
|
say "done."; |
60
|
1
|
|
|
|
|
1500
|
}); |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
33
|
say 'done!'; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |