Silki/CLI/Export.pm untested

filter: Statementstmt 0.0% 0 / 60 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 80 CC 2 SCAR 9.2
CC
2
Cov
0%
_run
6.0
_final_result_string
2.0
_print_success_message
2.0
CRAP 2.5
1 package Silki::CLI::Export;
2 {
3 $Silki::CLI::Export::VERSION = '0.29';
4 }
5  
6 use strict;
7 use warnings;
8 use namespace::autoclean;
9 use autodie;
10  
11 use Cwd qw( abs_path );
12 use Path::Class qw( dir );
13 use Silki::Schema::Process;
14 use Silki::Schema::Wiki;
15 use Silki::Types qw( Str );
16 use Silki::Wiki::Exporter;
17  
18 use Moose;
19 use Moose::Util::TypeConstraints;
20  
21 with qw( MooseX::Getopt::Dashes Silki::Role::CLI::HasOptionalProcess );
22  
23 {
24 subtype 'Wiki', as 'Silki::Schema::Wiki';
25 coerce 'Wiki',
26 from Str,
27 via { Silki::Schema::Wiki->new( short_name => $_ ) };
28  
29 MooseX::Getopt::OptionTypeMap->add_option_type_to_map( 'Wiki' => '=s' );
30  
31 has wiki => (
32 is => 'ro',
33 isa => 'Wiki',
34 required => 1,
35 coerce => 1,
36 documentation => 'The short name of the wiki to export. Required.',
37 );
38 }
39  
40 has file => (
41 is => 'ro',
42 isa => Str,
43 predicate => '_has_file',
44 documentation =>
45 'The name of the tarball to be created.'
46 . ' If not specified, the tarball is created as'
47 . ' export-of-<short-name>.tar.gz in the current directory',
48 );
49  
50 sub _run {
51 my $self = shift;
52  
53 my %p = (
54 wiki => $self->wiki(),
55 log => $self->_log_coderef(),
56 );
57  
58 my $tarball = Silki::Wiki::Exporter->new(%p)->tarball();
59  
60 my $new_name
61 = $self->_has_file()
62 ? $self->file()
63 : dir( abs_path() )->file( $tarball->basename() );
64  
65 rename $tarball => $new_name;
66  
67 return $new_name;
68 }
69  
70 sub _final_result_string {
71 my $self = shift;
72 my $tarball = shift;
73  
74 return $tarball;
75 }
76  
77 sub _print_success_message {
78 my $self = shift;
79 my $tarball = shift;
80  
81 print "\n";
82 print ' The '
83 . $self->wiki()->short_name()
84 . ' wiki has been exported at '
85 . $tarball;
86 print "\n\n";
87 }
88  
89 # Intentionally not made immutable, since we only ever make one of these
90 # objects in a process.
91  
92 1;