File Coverage

blib/lib/Dist/Zilla/Plugin/MetaData/BuiltWith/All.pm
Criterion Covered Total %
statement 46 52 88.4
branch 13 20 65.0
condition 5 9 55.5
subroutine 9 9 100.0
pod n/a
total 73 90 81.1


line stmt bran cond sub pod time code
1 2     2   1778624 use 5.006;
  2         7  
2 2     2   7 use strict;
  2         2  
  2         39  
3 2     2   15 use warnings;
  2         1  
  2         132  
4              
5             package Dist::Zilla::Plugin::MetaData::BuiltWith::All;
6              
7             our $VERSION = '1.004004';
8              
9             # ABSTRACT: Go overkill and report everything in all name-spaces.
10              
11             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12              
13 2     2   654 use Moose qw( extends has around );
  2         347159  
  2         15  
14 2     2   9816 use namespace::autoclean;
  2         5465  
  2         11  
15             extends 'Dist::Zilla::Plugin::MetaData::BuiltWith';
16              
17              
18              
19              
20              
21              
22              
23              
24              
25              
26              
27              
28              
29              
30              
31              
32              
33              
34              
35              
36              
37              
38              
39              
40              
41              
42              
43              
44              
45              
46              
47              
48              
49              
50              
51              
52              
53              
54              
55              
56              
57              
58              
59              
60              
61              
62              
63              
64              
65              
66              
67              
68              
69              
70              
71              
72              
73              
74              
75              
76              
77              
78             has 'show_failures' => ( is => 'ro', isa => 'Bool', default => 0 );
79              
80             around dump_config => sub {
81             my ( $orig, $self, @args ) = @_;
82             my $config = $self->$orig(@args);
83             my $payload = $config->{ +__PACKAGE__ } = {};
84             $payload->{show_failures} = $self->show_failures;
85             $payload->{ q[$] . __PACKAGE__ . q[::VERSION] } = $VERSION unless __PACKAGE__ eq ref $self;
86             return $config;
87             };
88              
89             around '_metadata' => sub {
90             my ( $orig, $self, @args ) = @_;
91             my $stash = $self->$orig(@args);
92             return { %{$stash}, %{ $self->_get_all() } };
93             };
94              
95             __PACKAGE__->meta->make_immutable;
96 2     2   461 no Moose;
  2         4  
  2         16  
97              
98             sub _list_modules_in_memory {
99 1248     1248   856 my ( $self, $package ) = @_;
100              
101 1248 100 66     3202 return $package if 'main' eq $package or $package =~ /\Amain::/msx;
102              
103 1247         688 my $ns = do {
104             ## no critic (ProhibitNoStrict)
105 2     2   265 no strict 'refs';
  2         3  
  2         601  
106 1247         678 \%{ $package . q{::} };
  1247         2245  
107             };
108 1247         755 my (@child_namespaces);
109 1247         654 for my $child ( keys %{$ns} ) {
  1247         4221  
110 14020 100       17223 next unless $child =~ /\A(.*)::$/msx;
111 1247         1119 my $child_pkg = $1;
112 1247 100       1751 $child_pkg = $package . q[::] . $child_pkg if $package;
113 1247         1204 push @child_namespaces, $child_pkg;
114             }
115              
116 1247   66     2556 return ( ( $package || () ), map { $self->_list_modules_in_memory($_) } @child_namespaces );
  1247         1244  
117             }
118              
119             sub _get_all {
120 1     1   1 my ($self) = @_;
121 1         2 my %modtable;
122             my %failures;
123              
124 1         3 for my $module ( $self->_list_modules_in_memory(q{}), $self->include ) {
125 1247 50       2025 if ( $module =~ /\A__ANON__/msx ) {
126 0         0 $failures{$module} = 'Skipped: Anonymous Class';
127 0         0 next;
128             }
129 1247 50       1836 if ( $module =~ /\[/msx ) {
130 0         0 $failures{$module} = 'Skipped: Parameterized Type';
131 0         0 next;
132             }
133 1247         2692 my $result = $self->_detect_installed($module);
134              
135 1247 100       3318 $modtable{$module} = $result->[0] if defined $result->[0];
136 1247 100       4173 $failures{$module} = $result->[1] if defined $result->[1];
137              
138             }
139              
140 1         171 for my $badmodule ( $self->exclude ) {
141 0 0       0 delete $modtable{$badmodule} if exists $modtable{$badmodule};
142 0 0       0 delete $failures{$badmodule} if exists $failures{$badmodule};
143             }
144 1         5 my $rval = { allmodules => \%modtable };
145 1 50 33     40 $rval->{allfailures} = \%failures if keys %failures and $self->show_failures;
146 1         425 return $rval;
147             }
148              
149             1;
150              
151             __END__
152              
153             =pod
154              
155             =encoding UTF-8
156              
157             =head1 NAME
158              
159             Dist::Zilla::Plugin::MetaData::BuiltWith::All - Go overkill and report everything in all name-spaces.
160              
161             =head1 VERSION
162              
163             version 1.004004
164              
165             =head1 SYNOPSIS
166              
167             [MetaData::BuiltWith::All]
168             show_failures = 1 ; Not recommended
169              
170             This module is otherwise identical to L<< C<MetaData::BuiltWith>|Dist::Zilla::Plugin::MetaData::BuiltWith >>.
171              
172             =head1 DESCRIPTION
173              
174             This further extends the verbosity of the information reported by the L<< C<BuiltWith>|Dist::Zilla::Plugin::MetaData::BuiltWith >> plug-in,
175             by recursively rooting around in the name-spaces and reporting every version of everything it finds.
176              
177             Only recommended for the most extreme of situations where you find your code breaking all over the show between different versions of things, or for personal amusement.
178              
179             =head1 OPTIONS
180              
181             =head2 show_failures
182              
183             Because this module reports B<ALL> C<namespaces>, it will likely report very many C<namespaces>
184             which simply do not exist on disk as a distinct file, and as a result, are unlikely to have C<$VERSION> data.
185              
186             As a result, enabling this option will drop a mother load of failures into a hash somewhere in C<x_BuiltWith>.
187              
188             For instance, there's one for every single package in C<B::>
189              
190             And there's one for every single instance of C<Eval::Closure::Sandbox> named C<Eval::Closure::Sandbox_.*>
191              
192             There's one for every instance of C<Module::Metadata> ( I spotted about 80 myself )
193              
194             And there's one for each and every thing that uses C<__ANON__::>
195              
196             You get the idea?
197              
198             B<Do not turn this option on>
199              
200             You have been warned.
201              
202             =head2 exclude
203              
204             Specify modules to exclude from version reporting
205              
206             exclude = Foo
207             exclude = Bar
208              
209             =head2 include
210              
211             Specify additional modules to include the version of
212              
213             include = Foo
214             include = Bar
215              
216             =head2 show_config
217              
218             Report "interesting" values from C<%Config::Config>
219              
220             show_config = 1 ; Boolean
221              
222             =head2 show_uname
223              
224             Report the output from C<uname>
225              
226             show_uname = 1 ; Boolean
227              
228             =head2 uname_call
229              
230             Specify what the system C<uname> function is called
231              
232             uname_call = uname ; String
233              
234             =head2 uname_args
235              
236             Specify arguments passed to the C<uname> call.
237              
238             uname_args = -a ; String
239              
240             =head1 WARNING
241              
242             At present this code does no recursion prevention, apart from excluding the C<main> name-space.
243              
244             If it sees other name-spaces which recur into their self indefinitely ( like main does ), then it may not terminate normally.
245              
246             Also, using this module will likely add 1000 lines to C<META.yml>, so please for the love of sanity don't use this too often.
247              
248             =head1 AUTHOR
249              
250             Kent Fredric <kentnl@cpan.org>
251              
252             =head1 COPYRIGHT AND LICENSE
253              
254             This software is copyright (c) 2016 by Kent Fredric <kentnl@cpan.org>.
255              
256             This is free software; you can redistribute it and/or modify it under
257             the same terms as the Perl 5 programming language system itself.
258              
259             =cut