File Coverage

blib/lib/Dist/Zilla/Role/ModuleInfo.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             #---------------------------------------------------------------------
2             package Dist::Zilla::Role::ModuleInfo;
3             #
4             # Copyright 2010 Christopher J. Madsen
5             #
6             # Author: Christopher J. Madsen <perl@cjmweb.net>
7             # Created: 25 Sep 2009
8             #
9             # This program is free software; you can redistribute it and/or modify
10             # it under the same terms as Perl itself.
11             #
12             # This program is distributed in the hope that it will be useful,
13             # but WITHOUT ANY WARRANTY; without even the implied warranty of
14             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the
15             # GNU General Public License or the Artistic License for more details.
16             #
17             # ABSTRACT: Create Module::Metadata object from Dist::Zilla::File
18             #---------------------------------------------------------------------
19              
20             our $VERSION = '4.22';
21             # This file is part of Dist-Zilla-Plugins-CJM 4.26 (December 13, 2014)
22              
23 1     1   1649 use Moose::Role;
  0            
  0            
24              
25             use autodie ':io';
26             use File::Temp 0.19 (); # need newdir
27             use Module::Metadata ();
28             use Path::Class qw(dir file);
29              
30              
31             sub get_module_info
32             {
33             my $self = shift;
34             my $file = shift;
35             # Any additional parameters get passed to M::Metadata->new_from_file
36              
37             # To be safe, reset the global variables controlling IO to their defaults:
38             local ($/, $,, $\) = "\n";
39              
40             # Module::Metadata doesn't have a new_from_string method,
41             # so we'll write the current contents to a temporary file:
42              
43             my $tempdirObject = File::Temp->newdir();
44             my $dir = dir("$tempdirObject");
45             my $modPath = file($file->name);
46              
47             # Module::Metadata only cares about the basename of the file:
48             my $tempname = $dir->file($modPath->basename);
49              
50             open(my $temp, '>:raw', $tempname);
51             print $temp Dist::Zilla->VERSION < 5 ? $file->content : $file->encoded_content;
52             close $temp;
53              
54             return(Module::Metadata->new_from_file("$tempname", @_)
55             or die "Unable to get module info from " . $file->name . "\n");
56             } # end get_module_info
57              
58             no Moose::Role;
59             1;
60              
61             __END__
62              
63             =head1 NAME
64              
65             Dist::Zilla::Role::ModuleInfo - Create Module::Metadata object from Dist::Zilla::File
66              
67             =head1 VERSION
68              
69             This document describes version 4.22 of
70             Dist::Zilla::Role::ModuleInfo, released December 13, 2014
71             as part of Dist-Zilla-Plugins-CJM version 4.26.
72              
73             =head1 DESCRIPTION
74              
75             Plugins implementing ModuleInfo may call their own C<get_module_info>
76             method to construct a L<Module::Metadata> object. (Module::Metadata
77             is the new name for Module::Build::ModuleInfo, now that it's been
78             split from the Module-Build distribution.)
79              
80             =head1 METHODS
81              
82             =head2 get_module_info
83              
84             my $info = $plugin->get_module_info($file);
85              
86             This constructs a Module::Metadata object from the contents
87             of a C<$file> object that does Dist::Zilla::Role::File. Any additional
88             arguments are passed along to C<< Module::Metadata->new_from_file >>.
89              
90             =head1 CONFIGURATION AND ENVIRONMENT
91              
92             Dist::Zilla::Role::ModuleInfo requires no configuration files or environment variables.
93              
94             =head1 DEPENDENCIES
95              
96             L<Module::Metadata>.
97              
98             =head1 INCOMPATIBILITIES
99              
100             None reported.
101              
102             =head1 BUGS AND LIMITATIONS
103              
104             No bugs have been reported.
105              
106             =head1 AUTHOR
107              
108             Christopher J. Madsen S<C<< <perl AT cjmweb.net> >>>
109              
110             Please report any bugs or feature requests
111             to S<C<< <bug-Dist-Zilla-Plugins-CJM AT rt.cpan.org> >>>
112             or through the web interface at
113             L<< http://rt.cpan.org/Public/Bug/Report.html?Queue=Dist-Zilla-Plugins-CJM >>.
114              
115             You can follow or contribute to Dist-Zilla-Plugins-CJM's development at
116             L<< https://github.com/madsen/dist-zilla-plugins-cjm >>.
117              
118             =head1 COPYRIGHT AND LICENSE
119              
120             This software is copyright (c) 2014 by Christopher J. Madsen.
121              
122             This is free software; you can redistribute it and/or modify it under
123             the same terms as the Perl 5 programming language system itself.
124              
125             =head1 DISCLAIMER OF WARRANTY
126              
127             BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
128             FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
129             OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
130             PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
131             EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
132             WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
133             ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
134             YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
135             NECESSARY SERVICING, REPAIR, OR CORRECTION.
136              
137             IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
138             WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
139             REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENSE, BE
140             LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
141             OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
142             THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
143             RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
144             FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
145             SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
146             SUCH DAMAGES.
147              
148             =cut