| 1 | package CLI::Driver::Exec; | ||
| 2 | |||
| 3 | our $VERSION = '0.01'; | ||
| 4 | |||
| 5 | use Modern::Perl; | ||
| 6 | use Moose; | ||
| 7 | use namespace::autoclean; | ||
| 8 | use Method::Signatures; | ||
| 9 | use Data::Printer alias => 'pdump'; | ||
| 10 | use YAML (); | ||
| 11 | use Carp; | ||
| 12 | |||
| 13 | with 'Util::Medley::Roles::Attributes::List'; | ||
| 14 | |||
| 15 | ############################################################################## | ||
| 16 | # PUBLIC ATTRIBUTES | ||
| 17 | ############################################################################## | ||
| 18 | |||
| 19 | ############################################################################## | ||
| 20 | # PRIVATE_ATTRIBUTES | ||
| 21 | ############################################################################## | ||
| 22 | |||
| 23 | ############################################################################## | ||
| 24 | # PUBLIC METHODS | ||
| 25 | ############################################################################## | ||
| 26 | |||
| 27 | method sortDriverFile (Str :$driverFile!, | ||
| 28 | Bool :$writeStdout) { | ||
| 29 | |||
| 30 | $YAML::Preserve = 1; | ||
| 31 | $YAML::UseHeader = 0; | ||
| 32 | |||
| 33 | my $yaml = YAML::LoadFile($driverFile); | ||
| 34 | |||
| 35 | my @sorted = ('---'); | ||
| 36 | foreach my $key ( $self->List->nsort( keys %$yaml ) ) { | ||
| 37 | push @sorted, YAML::Dump( { $key => $yaml->{$key} } ); | ||
| 38 | } | ||
| 39 | |||
| 40 | my $sorted = join "\n", @sorted; | ||
| 41 | |||
| 42 | if ($writeStdout) { | ||
| 43 | print $sorted; | ||
| 44 | } | ||
| 45 | else { | ||
| 46 | open( my $fh, '>', $driverFile ) | ||
| 47 | or confess "failed to open $driverFile: $!"; | ||
| 48 | print $fh $sorted; | ||
| 49 | close($fh); | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | ############################################################################## | ||
| 54 | # PRIVATE METHODS | ||
| 55 | ############################################################################## | ||
| 56 | |||
| 57 | 1; |