Galileo/Command/dump.pm

filter: Statementstmt 96.5% 28 / 29 Branchbran 60.0% 6 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 82.0% 41 / 50 CC 7 SCAR 16.8
CC
7
Cov
83%
run
7.9
BEGIN
1.0
BEGIN
1.0
CRAP 5.4
« Galileo.pm ↑ Summary Galileo/Admin.pm »
1 package Galileo::Command::dump;
2 1 ▶use Mojo::Base 'Mojolicious::Command';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Mojo::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Mojo::Util qw/encode/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Getopt::Long qw/GetOptionsFromArray/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 has description => "Dump all stored pages as markdown\n";
8 1 has usage => <<END;
9 usage: $0 dump [options]
10 options:
11  
12 --directory,-d
13 An optional directory to dump to may be specified; the directory
14 must exist. By default it dumps to the current working directory.
15  
16 --title,-t
17 By default the title of the page is included as an HTML comment.
18 This option accepts an sprintf format for including the title.
19 As a special case, if this flag is given without argument, an h1
20 title is created.
21  
22 --encoding,-e
23 An encoding type. Defaults to UTF-8. Available encodings are the
24 same as Encode module of Perl.
25 END
26  
27 2 ▶sub run {
Subroutine run: called CC=7 SCAR=20.6
Pod documented
28 2 my $self = shift;
29  
30 2 GetOptionsFromArray( \@_,
31 'directory=s' => \my $dir,
32 'title:s' => \(my $title = '<!-- %s -->'),
33 'encoding:s' => \(my $encoding = 'UTF-8'),
34 );
35  
36 2 ▶ $title = '# %s' unless $title;
Branch: 1 branch
BranchTrueFalseTotal
unless $title 0 2 2
37 2 ▶ if ( $dir and ! -d $dir ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir and not -d $dir) 0 2 2
Condition33%1/3
$dir and not -d $dir
!ll&&!rl&&r
020
MC/DC0%0/2
$dir and not -d $dir
$dir not -d $dir
Truth table33%1/3
A and not(B)
A= $dirB= not -d $dir
ABresult
0X0
100
111
38 0 die qq{Directory "$dir" does not exist\n};
39 }
40  
41 2 my $pages = $self->app->schema->resultset('Page')->search;
42 2 ▶ while ( my $page = $pages->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $page = $pages->next) 7 2 9
43 7 my $file = Mojo::File->new($page->name . '.md');
44 7 ▶ $file = Mojo::File->new($dir)->child("$file") if $dir;
Branch: 1 branch
BranchTrueFalseTotal
if $dir 7 0 7
45  
46 7 my $content = sprintf "$title\n", $page->title;
47 7 $content .= $page->md;
48 7 ▶ $content = encode($encoding, $content) if $encoding;
Branch: 1 branch
BranchTrueFalseTotal
if $encoding 7 0 7
49  
50 7 $file->spurt($content);
51 }
52  
53 2 say "Export Complete";
54 }
55  
56 1 1;
57  
58  
« Galileo.pm ↑ Summary Galileo/Admin.pm »