| 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
| |||||||||||||||||||||||||||||
| 37 | 2 | ▶ | if ( $dir and ! -d $dir ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$dir and not -d $dir
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 43 | 7 | my $file = Mojo::File->new($page->name . '.md'); | |||||||||||||||||||||||||||
| 44 | 7 | ▶ | $file = Mojo::File->new($dir)->child("$file") if $dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 7 | $file->spurt($content); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 2 | say "Export Complete"; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 1 | 1; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||