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