File Coverage

blib/lib/Test/Apocalypse/AutoLoader.pm
Criterion Covered Total %
statement 11 13 84.6
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 16 18 88.8


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 73     73   292 use strict; use warnings;
  73     73   73  
  73         2482  
  73         292  
  73         73  
  73         3650  
10             package Test::Apocalypse::AutoLoader;
11             $Test::Apocalypse::AutoLoader::VERSION = '1.006';
12             BEGIN {
13 73     73   949 $Test::Apocalypse::AutoLoader::AUTHORITY = 'cpan:APOCAL';
14             }
15              
16             # ABSTRACT: Plugin for Test::AutoLoader
17              
18 73     73   219 use Test::More;
  73         73  
  73         438  
19 73     73   29784 use Test::AutoLoader 0.03;
  0            
  0            
20             use YAML 0.70;
21              
22             sub do_test {
23             # does META.yml exist?
24             if ( -e 'META.yml' and -f _ ) {
25             _load_yml( 'META.yml' );
26             } else {
27             # maybe one directory up?
28             if ( -e '../META.yml' and -f _ ) {
29             _load_yml( '../META.yml' );
30             } else {
31             plan tests => 1;
32             fail( 'META.yml is missing, unable to process it!' );
33             }
34             }
35              
36             return;
37             }
38              
39             # loads a yml file
40             sub _load_yml {
41             # we'll load a file
42             my $file = shift;
43              
44             # okay, proceed to load it!
45             my $data;
46             eval {
47             $data = YAML::LoadFile( $file );
48             };
49             if ( $@ ) {
50             plan tests => 1;
51             fail( "Unable to load $file => $@" );
52             return;
53             }
54              
55             # massage the data
56             $data = $data->{'provides'};
57              
58             # Okay, how many modules do we have?
59             if ( scalar keys %$data > 0 ) {
60             plan tests => scalar keys %$data;
61             } else {
62             plan skip_all => "No provided modules found in META.yml";
63             }
64              
65             # analyze every one of them!
66             foreach my $module ( keys %$data ) {
67             if ( _module_has_autoload( $module ) ) {
68             autoload_ok( $module );
69             } else {
70             pass( "Skipping '$module' because it has no autoloaded files" );
71             }
72             }
73              
74             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             my $pkg = shift;
80             my $dirname;
81              
82             if (defined($dirname = $INC{"$pkg.pm"})) {
83             if ( $^O eq 'MacOS' ) {
84             $pkg =~ tr#/#:#;
85             $dirname =~ s#^(.*)$pkg\.pm\z#$1auto:$pkg#s;
86             } else {
87             $dirname =~ s#^(.*)$pkg\.pm\z#$1auto/$pkg#s;
88             }
89             }
90             unless (defined $dirname and -d $dirname && -r _ ) {
91             return 0;
92             } else {
93             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.006 of Test::Apocalypse::AutoLoader - released October 25, 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