App-CISetup
view release on metacpan or search on metacpan
lib/App/CISetup/Role/ConfigFile.pm view on Meta::CPAN
package App::CISetup::Role::ConfigFile;
use strict;
use warnings;
use namespace::autoclean;
use autodie qw( :all );
our $VERSION = '0.19';
use App::CISetup::Types qw( Path );
use Try::Tiny;
use YAML qw( Dump LoadFile );
use Moose::Role;
requires qw(
_cisetup_flags
_create_config
_fix_up_yaml
_update_config
);
has file => (
is => 'ro',
isa => Path,
coerce => 1,
required => 1,
);
sub create_file {
my $self = shift;
$self->file->spew( $self->_config_to_yaml( $self->_create_config ) );
return;
}
sub update_file {
my $self = shift;
my $file = $self->file;
my $orig = $file->slurp;
my $content = try {
LoadFile($file);
}
catch {
die "YAML parsing error: $_\n";
};
return 0 unless $content;
my $config = $self->_update_config($content);
my $yaml = $self->_config_to_yaml($config);
return 0 if $yaml eq $orig;
$file->spew($yaml);
return 1;
}
sub _config_to_yaml {
my $self = shift;
my $config = shift;
## no critic (TestingAndDebugging::ProhibitNoWarnings, Variables::ProhibitPackageVars)
no warnings 'once';
# If Perl versions aren't quotes then Travis displays 5.10 as "5.1"
local $YAML::QuoteNumericStrings = 1;
( run in 0.907 second using v1.01-cache-2.11-cpan-39bf76dae61 )