File Coverage

blib/lib/Test/Apocalypse/AutoLoader.pm
Criterion Covered Total %
statement 36 50 72.0
branch 6 16 37.5
condition 2 9 22.2
subroutine 9 9 100.0
pod 0 1 0.0
total 53 85 62.3


line stmt bran cond sub pod time code
1             #
2             # This file is part of Test-Apocalypse
3             #
4             # This software is copyright (c) 2014 by Apocalypse.
5             #
6             # This is free software; you can redistribute it and/or modify it under
7             # the same terms as the Perl 5 programming language system itself.
8             #
9 75     75   375 use strict; use warnings;
  75     75   150  
  75         2925  
  75         300  
  75         150  
  75         4650  
10             package Test::Apocalypse::AutoLoader;
11             $Test::Apocalypse::AutoLoader::VERSION = '1.003';
12             BEGIN {
13 75     75   900 $Test::Apocalypse::AutoLoader::AUTHORITY = 'cpan:APOCAL';
14             }
15              
16             # ABSTRACT: Plugin for Test::AutoLoader
17              
18 75     75   300 use Test::More;
  75         150  
  75         525  
19 75     75   57450 use Test::AutoLoader 0.03;
  75         79050  
  75         3900  
20 75     75   33450 use YAML 0.70;
  75         405300  
  75         27075  
21              
22             sub do_test {
23             # does META.yml exist?
24 75 50 33 75 0 1800 if ( -e 'META.yml' and -f _ ) {
25 75         150 _load_yml( 'META.yml' );
26             } else {
27             # maybe one directory up?
28 0 0 0     0 if ( -e '../META.yml' and -f _ ) {
29 0         0 _load_yml( '../META.yml' );
30             } else {
31 0         0 plan tests => 1;
32 0         0 fail( 'META.yml is missing, unable to process it!' );
33             }
34             }
35              
36 75         525 return;
37             }
38              
39             # loads a yml file
40             sub _load_yml {
41             # we'll load a file
42 75     75   150 my $file = shift;
43              
44             # okay, proceed to load it!
45 75         75 my $data;
46 75         150 eval {
47 75         225 $data = YAML::LoadFile( $file );
48             };
49 75 50       18957900 if ( $@ ) {
50 0         0 plan tests => 1;
51 0         0 fail( "Unable to load $file => $@" );
52 0         0 return;
53             }
54              
55             # massage the data
56 75         300 $data = $data->{'provides'};
57              
58             # Okay, how many modules do we have?
59 75 50       12975 if ( scalar keys %$data > 0 ) {
60 75         525 plan tests => scalar keys %$data;
61             } else {
62 0         0 plan skip_all => "No provided modules found in META.yml";
63             }
64              
65             # analyze every one of them!
66 75         28500 foreach my $module ( keys %$data ) {
67 2775 50       794550 if ( _module_has_autoload( $module ) ) {
68 0         0 autoload_ok( $module );
69             } else {
70 2775         8625 pass( "Skipping '$module' because it has no autoloaded files" );
71             }
72             }
73              
74 75         24000 return;
75             }
76              
77             # basically ripped off from Test::AutoLoader so we don't get the annoying "unable to find autoload directory" failure
78             sub _module_has_autoload {
79 2775     2775   3225 my $pkg = shift;
80 2775         2325 my $dirname;
81              
82 2775 50       9975 if (defined($dirname = $INC{"$pkg.pm"})) {
83 0 0       0 if ( $^O eq 'MacOS' ) {
84 0         0 $pkg =~ tr#/#:#;
85 0         0 $dirname =~ s#^(.*)$pkg\.pm\z#$1auto:$pkg#s;
86             } else {
87 0         0 $dirname =~ s#^(.*)$pkg\.pm\z#$1auto/$pkg#s;
88             }
89             }
90 2775 50 33     7200 unless (defined $dirname and -d $dirname && -r _ ) {
91 2775         6000 return 0;
92             } else {
93 0           return 1;
94             }
95             }
96              
97             1;
98              
99             __END__
100              
101             =pod
102              
103             =encoding UTF-8
104              
105             =for :stopwords Apocalypse Niebur Ryan
106              
107             =for Pod::Coverage do_test
108              
109             =head1 NAME
110              
111             Test::Apocalypse::AutoLoader - Plugin for Test::AutoLoader
112              
113             =head1 VERSION
114              
115             This document describes v1.003 of Test::Apocalypse::AutoLoader - released October 24, 2014 as part of Test-Apocalypse.
116              
117             =head1 DESCRIPTION
118              
119             Encapsulates L<Test::AutoLoader> functionality.
120              
121             =head1 SEE ALSO
122              
123             Please see those modules/websites for more information related to this module.
124              
125             =over 4
126              
127             =item *
128              
129             L<Test::Apocalypse|Test::Apocalypse>
130              
131             =back
132              
133             =head1 AUTHOR
134              
135             Apocalypse <APOCAL@cpan.org>
136              
137             =head1 COPYRIGHT AND LICENSE
138              
139             This software is copyright (c) 2014 by Apocalypse.
140              
141             This is free software; you can redistribute it and/or modify it under
142             the same terms as the Perl 5 programming language system itself.
143              
144             The full text of the license can be found in the
145             F<LICENSE> file included with this distribution.
146              
147             =head1 DISCLAIMER OF WARRANTY
148              
149             THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
150             APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
151             HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
152             OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
153             THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
154             PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
155             IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
156             ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
157              
158             IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
159             WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
160             THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
161             GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
162             USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
163             DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
164             PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
165             EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
166             SUCH DAMAGES.
167              
168             =cut