| 1 | package Dist::Zilla::Role::FileFinderUser 6.040; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: something that uses FileFinder plugins | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 18 | ▶ | use MooseX::Role::Parameterized 1.01; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 18 | ▶ | use Dist::Zilla::Pragmas; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 18 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | #pod =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 11 | #pod | ||||||||||||||||||||||||||||
| 12 | #pod This role enables you to search for files in the dist. This makes it easy to find specific | ||||||||||||||||||||||||||||
| 13 | #pod files and have the code factored out to common methods. | ||||||||||||||||||||||||||||
| 14 | #pod | ||||||||||||||||||||||||||||
| 15 | #pod Here's an example of a finder: ( taken from AutoPrereqs ) | ||||||||||||||||||||||||||||
| 16 | #pod | ||||||||||||||||||||||||||||
| 17 | #pod with 'Dist::Zilla::Role::FileFinderUser' => { | ||||||||||||||||||||||||||||
| 18 | #pod default_finders => [ ':InstallModules', ':ExecFiles' ], | ||||||||||||||||||||||||||||
| 19 | #pod }; | ||||||||||||||||||||||||||||
| 20 | #pod | ||||||||||||||||||||||||||||
| 21 | #pod Then you use it in your code like this: | ||||||||||||||||||||||||||||
| 22 | #pod | ||||||||||||||||||||||||||||
| 23 | #pod foreach my $file ( @{ $self->found_files }) { | ||||||||||||||||||||||||||||
| 24 | #pod # $file is an object! Look at L<Dist::Zilla::Role::File> | ||||||||||||||||||||||||||||
| 25 | #pod } | ||||||||||||||||||||||||||||
| 26 | #pod | ||||||||||||||||||||||||||||
| 27 | #pod =cut | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | #pod =attr finder_arg_names | ||||||||||||||||||||||||||||
| 30 | #pod | ||||||||||||||||||||||||||||
| 31 | #pod Define the name of the attribute which will hold this finder. Be sure to specify different names | ||||||||||||||||||||||||||||
| 32 | #pod if you have multiple finders! | ||||||||||||||||||||||||||||
| 33 | #pod | ||||||||||||||||||||||||||||
| 34 | #pod This is an ArrayRef. | ||||||||||||||||||||||||||||
| 35 | #pod | ||||||||||||||||||||||||||||
| 36 | #pod Default: [ qw( finder ) ] | ||||||||||||||||||||||||||||
| 37 | #pod | ||||||||||||||||||||||||||||
| 38 | #pod =cut | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | parameter finder_arg_names => ( | ||||||||||||||||||||||||||||
| 41 | isa => 'ArrayRef', | ||||||||||||||||||||||||||||
| 42 | 29 | ▶ | default => sub { [ 'finder' ] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 43 | 6 | ); | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | #pod =attr default_finders | ||||||||||||||||||||||||||||
| 46 | #pod | ||||||||||||||||||||||||||||
| 47 | #pod This attribute is an arrayref of plugin names for the default plugins the | ||||||||||||||||||||||||||||
| 48 | #pod consuming plugin will use as finders. | ||||||||||||||||||||||||||||
| 49 | #pod | ||||||||||||||||||||||||||||
| 50 | #pod Example: C<< [ qw( :InstallModules :ExecFiles ) ] >> | ||||||||||||||||||||||||||||
| 51 | #pod | ||||||||||||||||||||||||||||
| 52 | #pod The default finders are: | ||||||||||||||||||||||||||||
| 53 | #pod | ||||||||||||||||||||||||||||
| 54 | #pod =begin :list | ||||||||||||||||||||||||||||
| 55 | #pod | ||||||||||||||||||||||||||||
| 56 | #pod = :InstallModules | ||||||||||||||||||||||||||||
| 57 | #pod | ||||||||||||||||||||||||||||
| 58 | #pod Searches your lib/ directory for pm/pod files | ||||||||||||||||||||||||||||
| 59 | #pod | ||||||||||||||||||||||||||||
| 60 | #pod = :IncModules | ||||||||||||||||||||||||||||
| 61 | #pod | ||||||||||||||||||||||||||||
| 62 | #pod Searches your inc/ directory for pm files | ||||||||||||||||||||||||||||
| 63 | #pod | ||||||||||||||||||||||||||||
| 64 | #pod = :MainModule | ||||||||||||||||||||||||||||
| 65 | #pod | ||||||||||||||||||||||||||||
| 66 | #pod Finds the C<main_module> of your dist | ||||||||||||||||||||||||||||
| 67 | #pod | ||||||||||||||||||||||||||||
| 68 | #pod = :TestFiles | ||||||||||||||||||||||||||||
| 69 | #pod | ||||||||||||||||||||||||||||
| 70 | #pod Searches your t/ directory and lists the files in it. | ||||||||||||||||||||||||||||
| 71 | #pod | ||||||||||||||||||||||||||||
| 72 | #pod = :ExtraTestFiles | ||||||||||||||||||||||||||||
| 73 | #pod | ||||||||||||||||||||||||||||
| 74 | #pod Searches your xt/ directory and lists the files in it. | ||||||||||||||||||||||||||||
| 75 | #pod | ||||||||||||||||||||||||||||
| 76 | #pod = :ExecFiles | ||||||||||||||||||||||||||||
| 77 | #pod | ||||||||||||||||||||||||||||
| 78 | #pod Searches your distribution for executable files. Hint: Use the | ||||||||||||||||||||||||||||
| 79 | #pod L<Dist::Zilla::Plugin::ExecDir> plugin to mark those files as executables. | ||||||||||||||||||||||||||||
| 80 | #pod | ||||||||||||||||||||||||||||
| 81 | #pod = :PerlExecFiles | ||||||||||||||||||||||||||||
| 82 | #pod | ||||||||||||||||||||||||||||
| 83 | #pod A subset of C<:ExecFiles> limited just to perl scripts (those ending with | ||||||||||||||||||||||||||||
| 84 | #pod F<.pl>, or with a recognizable perl shebang). | ||||||||||||||||||||||||||||
| 85 | #pod | ||||||||||||||||||||||||||||
| 86 | #pod = :ShareFiles | ||||||||||||||||||||||||||||
| 87 | #pod | ||||||||||||||||||||||||||||
| 88 | #pod Searches your ShareDir directory and lists the files in it. | ||||||||||||||||||||||||||||
| 89 | #pod Hint: Use the L<Dist::Zilla::Plugin::ShareDir> plugin to set up the sharedir. | ||||||||||||||||||||||||||||
| 90 | #pod | ||||||||||||||||||||||||||||
| 91 | #pod = :AllFiles | ||||||||||||||||||||||||||||
| 92 | #pod | ||||||||||||||||||||||||||||
| 93 | #pod Returns all files in the distribution. | ||||||||||||||||||||||||||||
| 94 | #pod | ||||||||||||||||||||||||||||
| 95 | #pod = :NoFiles | ||||||||||||||||||||||||||||
| 96 | #pod | ||||||||||||||||||||||||||||
| 97 | #pod Returns nothing. | ||||||||||||||||||||||||||||
| 98 | #pod | ||||||||||||||||||||||||||||
| 99 | #pod =end :list | ||||||||||||||||||||||||||||
| 100 | #pod | ||||||||||||||||||||||||||||
| 101 | #pod =cut | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 6 | parameter default_finders => ( | |||||||||||||||||||||||||||
| 104 | isa => 'ArrayRef', | ||||||||||||||||||||||||||||
| 105 | required => 1, | ||||||||||||||||||||||||||||
| 106 | ); | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | #pod =attr method | ||||||||||||||||||||||||||||
| 109 | #pod | ||||||||||||||||||||||||||||
| 110 | #pod This will be the name of the subroutine installed in your package for this | ||||||||||||||||||||||||||||
| 111 | #pod finder. Be sure to specify different names if you have multiple finders! | ||||||||||||||||||||||||||||
| 112 | #pod | ||||||||||||||||||||||||||||
| 113 | #pod Default: found_files | ||||||||||||||||||||||||||||
| 114 | #pod | ||||||||||||||||||||||||||||
| 115 | #pod =cut | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 6 | parameter method => ( | |||||||||||||||||||||||||||
| 118 | isa => 'Str', | ||||||||||||||||||||||||||||
| 119 | default => 'found_files', | ||||||||||||||||||||||||||||
| 120 | ); | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 47 | ▶ | role { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||
| 123 | 47 | my ($p) = @_; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 47 | my ($finder_arg, @finder_arg_aliases) = @{ $p->finder_arg_names }; | |||||||||||||||||||||||||||
| 126 | 47 | ▶ | confess "no finder arg names given!" unless $finder_arg; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 156 | ▶ | around mvp_multivalue_args => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 129 | 156 | my ($orig, $self) = @_; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 156 | my @start = $self->$orig; | |||||||||||||||||||||||||||
| 132 | 156 | return (@start, $finder_arg); | |||||||||||||||||||||||||||
| 133 | 47 | }; | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 47 | ▶ | if (@finder_arg_aliases) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | around mvp_aliases => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 137 | 0 | my ($orig, $self) = @_; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | my $start = $self->$orig; | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | for my $alias (@finder_arg_aliases) { | |||||||||||||||||||||||||||
| 142 | confess "$alias is already an alias to $start->{$alias}" | ||||||||||||||||||||||||||||
| 143 | 0 | ▶ | if exists $start->{$alias} and $orig->{$alias} ne $finder_arg; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $start->{$alias} and $orig->{$alias} ne $finder_arg
MC/DC0%0/2
exists $start->{$alias} and $orig->{$alias} ne $finder_arg
exists $start->{$alias}
$orig->{$alias} ne $finder_arg
Truth table0%0/3
A and B
A= exists $start->{$alias}B= $orig->{$alias} ne $finder_arg
| |||||||||||||||||||||||||||||
| 144 | 0 | $start->{ $alias } = $finder_arg; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | return $start; | |||||||||||||||||||||||||||
| 148 | 0 | }; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | has $finder_arg => ( | ||||||||||||||||||||||||||||
| 152 | is => 'ro', | ||||||||||||||||||||||||||||
| 153 | isa => 'ArrayRef[Str]', | ||||||||||||||||||||||||||||
| 154 | 149 | ▶ | default => sub { [ @{ $p->default_finders } ] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 155 | 47 | ); | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 8 | ▶ | method $p->method => sub { | ||||||||||||||||||||||||||
|
Subroutine
found_files: called CC=1 SCAR=0.0
Subroutine
found_configure_files: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 158 | 8 | my ($self) = @_; | |||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 16 | my @filesets = map {; $self->zilla->find_files($_) } | |||||||||||||||||||||||||||
| 161 | 8 | @{ $self->$finder_arg }; | |||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 8 | my %by_name = map {; $_->name, $_ } map { @$_ } @filesets; | |||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 8 | return [ map {; $by_name{$_} } sort keys %by_name ]; | |||||||||||||||||||||||||||
| 166 | 47 | }; | |||||||||||||||||||||||||||
| 167 | 6 | }; | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 6 | 1; | |||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | __END__ | ||||||||||||||||||||||||||||