File Coverage

blib/lib/App/RL/Command/split.pm
Criterion Covered Total %
statement 43 45 95.5
branch 7 10 70.0
condition n/a
subroutine 11 11 100.0
pod 5 5 100.0
total 66 71 92.9


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