« Dist/Zilla/Plugin/DROLSKY/BundleAuthordep.pm
↑ Summary
Dist/Zilla/Plugin/DROLSKY/Contributors.pm »
| 1 | package Dist::Zilla::Plugin::DROLSKY::Role::MaybeFileWriter; | ||
| 2 | |||
| 3 | use v5.10; | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | use autodie; | ||
| 8 | use namespace::autoclean; | ||
| 9 | |||
| 10 | our $VERSION = '1.25'; | ||
| 11 | |||
| 12 | use Carp::Always; | ||
| 13 | use Path::Tiny qw( path ); | ||
| 14 | |||
| 15 | use Moose::Role; | ||
| 16 | |||
| 17 | ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) | ||
| 18 | sub _maybe_write_file { | ||
| 19 | my $self = shift; | ||
| 20 | my $path = shift; | ||
| 21 | my $content = shift; | ||
| 22 | my $is_executable = shift; | ||
| 23 | |||
| 24 | my $file = path($path); | ||
| 25 | |||
| 26 | return if $file->exists; | ||
| 27 | |||
| 28 | ## no critic (ValuesAndExpressions::ProhibitLeadingZeros ) | ||
| 29 | $file->parent->mkdir( { chmod => 0755 } ); | ||
| 30 | $file->spew_utf8($content); | ||
| 31 | $file->chmod(0755) if $is_executable; | ||
| 32 | |||
| 33 | return; | ||
| 34 | } | ||
| 35 | |||
| 36 | 1; | ||
| 37 | |||
| 38 | # ABSTRACT: Knows how to maybe write files | ||
| 39 | |||
| 40 | __END__ |