File Coverage

blib/lib/Module/Package.pm
Criterion Covered Total %
statement 9 28 32.1
branch 0 8 0.0
condition 1 6 16.6
subroutine 3 5 60.0
pod 0 1 0.0
total 13 48 27.0


line stmt bran cond sub pod time code
1             ##
2             # name: Module::Package
3             # abstract: Postmodern Perl Module Packaging
4             # author: Ingy döt Net
5             # license: perl
6             # copyright: 2011
7             # see:
8             # - Module::Package::Plugin
9             # - Module::Install::Package
10             # - Module::Package::Tutorial
11              
12             package Module::Package;
13 1     1   834 use 5.005;
  1         4  
  1         45  
14 1     1   8 use strict;
  1         2  
  1         80  
15              
16             BEGIN {
17 1     1   3 $Module::Package::VERSION = '0.30';
18 1   33     17 $inc::Module::Package::VERSION ||= $Module::Package::VERSION;
19 1         338 @inc::Module::Package::ISA = __PACKAGE__;
20             }
21              
22             sub import {
23 0     0     my $class = shift;
24 0           $INC{'inc/Module/Install.pm'} = __FILE__;
25 0 0         unshift @INC, 'inc' unless $INC[0] eq 'inc';
26 0 0         eval "use Module::Install 1.01 (); 1" or $class->error($@);
27              
28             package main;
29 0           Module::Install->import();
30 0           eval {
31 0           module_package_internals_version_check($Module::Package::VERSION);
32 0           module_package_internals_init(@_);
33             };
34 0 0         if ($@) {
35 0           $Module::Package::ERROR = $@;
36 0           die $@;
37             }
38             }
39              
40             # XXX Remove this when things are stable.
41             sub error {
42 0     0 0   my ($class, $error) = @_;
43 0 0 0       if (-e 'inc' and not -e 'inc/.author') {
44 0           require Data::Dumper;
45 0           $Data::Dumper::Sortkeys = 1;
46 0           my $dump1 = Data::Dumper::Dumper(\%INC);
47 0           my $dump2 = Data::Dumper::Dumper(\@INC);
48 0           die <<"...";
49             This should not have happened. Hopefully this dump will explain the problem:
50              
51             inc::Module::Package: $inc::Module::Package::VERSION
52             Module::Package: $Module::Package::VERSION
53             inc::Module::Install: $inc::Module::Install::VERSION
54             Module::Install: $Module::Install::VERSION
55              
56             Error: $error
57              
58             %INC:
59             $dump1
60             \@INC:
61             $dump2
62             ...
63             }
64             else {
65 0           die $error;
66             }
67             }
68              
69             1;
70              
71             =head1 SYNOPSIS
72              
73             In your C:
74              
75             use inc::Module::Package;
76              
77             or one of these invocations:
78              
79             # These two are functionally the same as above:
80             use inc::Module::Package ':basic';
81             use inc::Module::Package 'Plugin:basic';
82              
83             # With Module::Package::Catalyst plugin options
84             use inc::Module::Package 'Catalyst';
85              
86             # With Module::Package::Catalyst::common inline plugin class
87             use inc::Module::Package 'Catalyst:common';
88              
89             # Pass options to the Module::Package::Ingy::modern constructor
90             use inc::Module::Package 'Ingy:modern',
91             option1 => 'value1',
92             option2 => 'value2';
93              
94             =head1 DESCRIPTION
95              
96             This module is a dropin replacement for L. It does everything
97             Module::Install does, but just a bit better.
98              
99             Actually this module is simply a wrapper around Module::Install. It attempts
100             to drastically reduce what goes in a Makefile.PL, while at the same time,
101             fixing many of the problems that people have had with Module::Install (and
102             other module frameworks) over the years.
103              
104             =head1 PROPAGANDA
105              
106             Module::Install took Makefile.PL authoring from a black art to a small set of
107             powerful and reusable instructions. It allowed packaging gurus to take their
108             fancy tricks and make them into one liners for the rest of us.
109              
110             As the number of plugins has grown over the years, using Module::Install has
111             itself become a bit of a black art. It's become hard to know all the latest
112             tricks, put them in the correct order, and make sure you always use the
113             correct sets for your various Perl modules.
114              
115             Added to this is the fact that there are a few problems in Module::Install
116             design and general usage that are hard to fix and deploy with certainty that
117             it will work in all cases.
118              
119             This is where Module::Package steps in. Module::Package is the next logical
120             step in Makefile.PL authoring. It allows gurus to create well tested sets of
121             Module::Install directives, and lets the rest of us use Makefile.PLs that are
122             one line long. For example:
123              
124             use inc::Module::Package 'Catalyst:widget';
125              
126             could be the one line Makefile.PL for a Catalyst widget (whatever that is)
127             module distribution. Assuming someone creates a module called
128             Module::Package::Catalyst, with an inline class called
129             Module::Package::Catalyst::widget that inherited from
130             L.
131              
132             Module::Package is pragmatic. Even though you can do everything in one line,
133             you are still able to make any Module::Install calls as usual. Also you can
134             pass parameters to the Module::Package plugin.
135              
136             use inc::Module::Package 'Catalyst:widget',
137             deps_list => 0,
138             some_cataylst_thing => '...';
139              
140             # All Module::Install plugins still work!
141             requires 'Some::Module' => 3.14;
142              
143             This allows Module::Package::Catalyst to be configurable, even on the
144             properties like C that are inherited from
145             L.
146              
147             The point here is that with Module::Package, module packaging just got a whole
148             lot more powerful and simple. A rare combination!
149              
150             =head1 FEATURES
151              
152             Module::Package has many advantages over vanilla Module::Install.
153              
154             =head2 Smaller Makefile.PL Files
155              
156             In the majority of cases you can reduce your Makefile.PL to a single command.
157             The core Module::Package invokes the Module::Install plugins that it thinks
158             you want. You can also name the Module::Package plugin that does exactly the
159             plugins you want.
160              
161             =head2 Reduces Module::Install Bloat
162              
163             Somewhere Module::Install development went awry, and allowed modules that only
164             have useful code for an author, to be bundled into a distribution. Over time,
165             this has created a lot of wasted space on CPAN mirrors. Module::Package fixes
166             this.
167              
168             =head2 Collaborator Plugin Discovery
169              
170             An increasing problem with Module::Install is that when people check out your
171             module source from a repository, they don't know which Module::Install plugin
172             modules you have used. That's because the Makefile.PL only requires the
173             function names, not the module names that they come from.
174              
175             Many people have realized this problem, and worked around it in various
176             suboptimal ways. Module::Package manages this problem for you.
177              
178             =head2 Feature Grouping and Reuse
179              
180             Module::Install has lots of plugins. Although it is possible with plain
181             Module::Install, nobody seems to make plugins that group other plugins. This
182             also might introduce subtle problems of using groups with other groups.
183              
184             Module::Package has object oriented plugins whose main purpose is to create
185             these groups. They inherit base functionality, subclass it to their design
186             goals and can define options for the user to tweak how they will operate.
187              
188             =head1 USAGE
189              
190             The basic anatomy of a Makefile.PL call to Module::Package is:
191              
192             use inc::Module::Package 'PluginName:flavor ',
193             $option1 => $value1;
194              
195             The C part uses the Module::Install C bootstrapping
196             trick.
197              
198             C (note the single ':') resolves to the inline class
199             C, within the module
200             C. Module::Package::PluginName::flavor must be a
201             subclass of L.
202              
203             An optional version can be used after the plugin name.
204              
205             Optional key/value pairs can follow the Plugin specification. They are used to
206             pass information to the plugin. See Plugin docs for more details.
207              
208             If C<:flavor> is omitted, the class Module::Package::PluginName is
209             used. The idea is that you can create a single module with many different
210             plugin styles.
211              
212             If C is omitted, then C<:flavor> is used against
213             L. These are a set of common plugin classes that you
214             can use.
215              
216             If C is omitted altogether, it is the same as saying
217             'Plugin:basic'. Note that you need to specify the ':basic' plugin if you want
218             to also pass it options.
219              
220             =head1 STATUS
221              
222             This is still an early release. We are still shaking out the bugs. You might
223             want to hold off for a bit longer before using Module::Package for important
224             modules.