« CPAN/Maker/Bootstrapper/Role/DarkPANRequires.pm
↑ Summary
CPAN/Maker/Bootstrapper/Role/Filter.pm »
| 1 | package CPAN::Maker::Bootstrapper::Role::DistFile; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use CLI::Simple::Constants qw(:booleans); | ||
| 7 | use CLI::Simple::Utils qw(slurp); | ||
| 8 | use Data::Dumper; | ||
| 9 | use English qw(-no_match_vars); | ||
| 10 | use File::ShareDir qw(dist_dir); | ||
| 11 | |||
| 12 | use Role::Tiny; | ||
| 13 | |||
| 14 | ######################################################################## | ||
| 15 | sub cmd_dist_file { | ||
| 16 | ######################################################################## | ||
| 17 | my ($self) = @_; | ||
| 18 | |||
| 19 | my ( $distribution, $file ) = $self->get_args; | ||
| 20 | |||
| 21 | if ( !$file ) { | ||
| 22 | $file = $distribution; | ||
| 23 | $distribution = 'CPAN-Maker-Bootstrapper'; | ||
| 24 | } | ||
| 25 | |||
| 26 | die "usage: dist-file [--path-only] distribution file\n" | ||
| 27 | if !$file; | ||
| 28 | |||
| 29 | my ( $path, $content ) = eval { | ||
| 30 | my $dist_dir = dist_dir($distribution); | ||
| 31 | |||
| 32 | my ($path) = grep { -e $_ } ( "$dist_dir/$file", "$dist_dir/share/$file" ); | ||
| 33 | |||
| 34 | die "$file not found in $distribution\n" | ||
| 35 | if !$path; | ||
| 36 | |||
| 37 | return ( $path, !$self->get_path_only ? slurp($path) : q{} ); | ||
| 38 | }; | ||
| 39 | |||
| 40 | die "ERROR: could not fetch $file from $distribution\n$EVAL_ERROR" | ||
| 41 | if !$path || $EVAL_ERROR; | ||
| 42 | |||
| 43 | print {*STDOUT} $self->get_path_only ? $path : $content; | ||
| 44 | |||
| 45 | return $SUCCESS; | ||
| 46 | } | ||
| 47 | |||
| 48 | 1; |