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