File Coverage

blib/lib/App/RL/Command/split.pm
Criterion Covered Total %
statement 41 43 95.3
branch 7 10 70.0
condition n/a
subroutine 11 11 100.0
pod 6 6 100.0
total 65 70 92.8


line stmt bran cond sub pod time code
1             package App::RL::Command::split;
2 15     15   15827 use strict;
  15         47  
  15         623  
3 15     15   104 use warnings;
  15         45  
  15         651  
4 15     15   105 use autodie;
  15         37  
  15         129  
5              
6 15     15   105813 use App::RL -command;
  15         54  
  15         269  
7 15     15   8712 use App::RL::Common;
  15         40  
  15         11809  
8              
9             sub abstract {
10 2     2 1 99 return 'split runlist yaml files';
11             }
12              
13             sub opt_spec {
14             return (
15 4     4 1 36 [ "outdir|o=s", "output location, [stdout] for screen", { default => '.' } ],
16             [ "suffix|s=s", "extension of output files", { default => '.yml' } ],
17             { show_defaults => 1, }
18             );
19             }
20              
21             sub usage_desc {
22 4     4 1 51319 return "runlist split [options] ";
23             }
24              
25             sub description {
26 1     1 1 1305 my $desc;
27 1         5 $desc .= ucfirst(abstract) . ".\n";
28 1         3 return $desc;
29             }
30              
31             sub validate_args {
32 3     3 1 2967 my ( $self, $opt, $args ) = @_;
33              
34 3 100       6 if ( @{$args} != 1 ) {
  3         14  
35 1         3 my $message = "This command need one input file.\n\tIt found";
36 1         2 $message .= sprintf " [%s]", $_ for @{$args};
  1         3  
37 1         5 $message .= ".\n";
38 1         8 $self->usage_error($message);
39             }
40 2         7 for ( @{$args} ) {
  2         11  
41 2 50       12 next if lc $_ eq "stdin";
42 2 100       16 if ( !Path::Tiny::path($_)->is_file ) {
43 1         155 $self->usage_error("The input file [$_] doesn't exist.");
44             }
45             }
46              
47 1 50       90 if ( !exists $opt->{outdir} ) {
48 0         0 $opt->{outdir} = Path::Tiny::path( $args->[0] )->absolute . ".split";
49             }
50             }
51              
52             sub execute {
53 1     1 1 9 my ( $self, $opt, $args ) = @_;
54              
55 1         7 my $yml = YAML::Syck::LoadFile( $args->[0] );
56              
57 1         431 for my $key ( keys %{$yml} ) {
  1         8  
58 16 50       526 if ( lc( $opt->{outdir} ) eq "stdout" ) {
59 16         37 print YAML::Syck::Dump( $yml->{$key} );
60             }
61             else {
62             YAML::Syck::DumpFile( Path::Tiny::path( $opt->{outdir}, $key . $opt->{suffix} ),
63 0           $yml->{$key} );
64             }
65             }
66             }
67              
68             1;