File Coverage

blib/lib/Dist/Zilla/Plugin/ModuleShareDirs.pm
Criterion Covered Total %
statement 13 23 56.5
branch 2 2 100.0
condition n/a
subroutine 4 5 80.0
pod 0 2 0.0
total 19 32 59.3


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::ModuleShareDirs 6.030;
2             # ABSTRACT: install a directory's contents as module-based "ShareDir" content
3              
4 2     2   2097 use Moose;
  2         7  
  2         20  
5              
6 2     2   15292 use Dist::Zilla::Pragmas;
  2         5  
  2         21  
7              
8 2     2   22 use namespace::autoclean;
  2         4  
  2         38  
9              
10             #pod =head1 SYNOPSIS
11             #pod
12             #pod In your F<dist.ini>:
13             #pod
14             #pod [ModuleShareDirs]
15             #pod Foo::Bar = shares/foo_bar
16             #pod Foo::Baz = shares/foo_baz
17             #pod
18             #pod =cut
19              
20             has _module_map => (
21             is => 'ro',
22             isa => 'HashRef',
23             default => sub { {} },
24             );
25              
26             sub find_files {
27 0     0 0 0 my ($self) = @_;
28 0         0 my $modmap = $self->_module_map;
29 0         0 my @files;
30              
31 0         0 for my $mod ( keys %$modmap ) {
32 0         0 my $dir = $modmap->{$mod};
33 0         0 my @mod_files = grep { index($_->name, "$dir/") == 0 }
34 0         0 @{ $self->zilla->files };
  0         0  
35 0         0 push @files, @mod_files;
36             }
37              
38 0         0 return \@files;
39             }
40              
41             sub share_dir_map {
42 7     7 0 25 my ($self) = @_;
43 7         271 my $modmap = $self->_module_map;
44              
45 7 100       44 return unless keys %$modmap;
46 5         33 return { module => $modmap };
47             }
48              
49             around BUILDARGS => sub {
50             my $orig = shift;
51             my ($class, @arg) = @_;
52              
53             my $args = $class->$orig(@arg);
54             my %copy = %{ $args };
55              
56             my $zilla = delete $copy{zilla};
57             my $name = delete $copy{plugin_name};
58              
59             return {
60             zilla => $zilla,
61             plugin_name => $name,
62             _module_map => \%copy,
63             }
64             };
65              
66             with 'Dist::Zilla::Role::ShareDir';
67             __PACKAGE__->meta->make_immutable;
68             1;
69              
70             __END__
71              
72             =pod
73              
74             =encoding UTF-8
75              
76             =head1 NAME
77              
78             Dist::Zilla::Plugin::ModuleShareDirs - install a directory's contents as module-based "ShareDir" content
79              
80             =head1 VERSION
81              
82             version 6.030
83              
84             =head1 SYNOPSIS
85              
86             In your F<dist.ini>:
87              
88             [ModuleShareDirs]
89             Foo::Bar = shares/foo_bar
90             Foo::Baz = shares/foo_baz
91              
92             =head1 PERL VERSION
93              
94             This module should work on any version of perl still receiving updates from
95             the Perl 5 Porters. This means it should work on any version of perl released
96             in the last two to three years. (That is, if the most recently released
97             version is v5.40, then this module should work on both v5.40 and v5.38.)
98              
99             Although it may work on older versions of perl, no guarantee is made that the
100             minimum required version will not be increased. The version may be increased
101             for any reason, and there is no promise that patches will be accepted to lower
102             the minimum required perl.
103              
104             =head1 AUTHOR
105              
106             Ricardo SIGNES 😏 <cpan@semiotic.systems>
107              
108             =head1 COPYRIGHT AND LICENSE
109              
110             This software is copyright (c) 2023 by Ricardo SIGNES.
111              
112             This is free software; you can redistribute it and/or modify it under
113             the same terms as the Perl 5 programming language system itself.
114              
115             =cut