File Coverage

blib/lib/Dist/Zilla/Plugin/Dpkg.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             package Dist::Zilla::Plugin::Dpkg;
2             {
3             $Dist::Zilla::Plugin::Dpkg::VERSION = '0.05';
4             }
5 1     1   32110 use Moose;
  0            
  0            
6              
7             # * copyright
8             # * docs
9             # * files
10             # * manpage.1
11             # * manpage.sgml
12             # * manpage.xml
13             # * menu
14             # * preinst
15             # * prerm
16             # * cron.d
17             # * doc-base
18             # * substvars
19             # * templates
20             # * watch
21              
22             # ABSTRACT: Generate Dpkg files for your perl module
23              
24              
25             use Dist::Zilla::File::InMemory;
26             use Text::Template;
27              
28             with 'Dist::Zilla::Role::InstallTool';
29              
30              
31             has 'architecture' => (
32             is => 'ro',
33             isa => 'Str',
34             default => 'any'
35             );
36              
37              
38             has 'compat_template' => (
39             is => 'ro',
40             isa => 'Str',
41             predicate => 'has_compat_template'
42             );
43              
44              
45             has 'compat_template_default' => (
46             is => 'ro',
47             isa => 'Str',
48             predicate => 'has_compat_template_default',
49             default => "7\n"
50             );
51              
52              
53             has 'conffiles_template' => (
54             is => 'ro',
55             isa => 'Str',
56             predicate => 'has_conffiles_template'
57             );
58              
59              
60             has 'conffiles_template_default' => (
61             is => 'ro',
62             isa => 'Str',
63             predicate => 'has_conffiles_template_default'
64             );
65              
66              
67             has 'config_template' => (
68             is => 'ro',
69             isa => 'Str',
70             predicate => 'has_config_template'
71             );
72              
73              
74             has 'config_template_default' => (
75             is => 'ro',
76             isa => 'Str',
77             predicate => 'has_config_template_default',
78             );
79              
80              
81             has 'control_template' => (
82             is => 'ro',
83             isa => 'Str',
84             predicate => 'has_control_template'
85             );
86              
87              
88             has 'control_template_default' => (
89             is => 'ro',
90             isa => 'Str',
91             predicate => 'has_control_template_default',
92             default => 'Source: {$package_name}
93             Section: {$package_section}
94             Priority: {$package_priority}
95             Maintainer: {$author}
96             Build-Depends: {$package_depends}
97             Standards-Version: 3.8.4
98              
99             Package: {$package_name}
100             Architecture: {$architecture}
101             Depends: {$package_binary_depends}
102             Description: {$package_description}
103             '
104             );
105              
106              
107             has 'default_template' => (
108             is => 'ro',
109             isa => 'Str',
110             predicate => 'has_default_template'
111             );
112              
113              
114             has 'default_template_default' => (
115             is => 'ro',
116             isa => 'Str',
117             predicate => 'has_default_template_default'
118             );
119              
120              
121             has 'init_template' => (
122             is => 'ro',
123             isa => 'Str',
124             predicate => 'has_init_template'
125             );
126              
127              
128             has 'init_template_default' => (
129             is => 'ro',
130             isa => 'Str',
131             predicate => 'has_init_template_default'
132             );
133              
134              
135             has 'install_template' => (
136             is => 'ro',
137             isa => 'Str',
138             predicate => 'has_install_template'
139             );
140              
141              
142             has 'install_template_default' => (
143             is => 'ro',
144             isa => 'Str',
145             predicate => 'has_install_template_default'
146             );
147              
148              
149             has 'package_depends' => (
150             is => 'ro',
151             isa => 'Str',
152             default => 'debhelper (>= 7.0.50~)'
153             );
154              
155              
156             has 'package_binary_depends' => (
157             is => 'ro',
158             isa => 'Str',
159             default => '${misc:Depends}, ${shlibs:Depends}, ${perl:Depends}'
160             );
161              
162              
163             has 'package_description' => (
164             is => 'ro',
165             isa => 'Str',
166             default => '<single line synopsis>
167             <extended description over several lines>'
168             );
169              
170              
171             has 'package_name' => (
172             is => 'ro',
173             isa => 'Str',
174             lazy => 1,
175             default => sub {
176             my $self = shift;
177             return lc($self->zilla->name)
178             }
179             );
180              
181              
182             has 'package_priority' => (
183             is => 'ro',
184             isa => 'Str',
185             default => 'extra'
186             );
187              
188              
189             has 'package_section' => (
190             is => 'ro',
191             isa => 'Str',
192             default => 'lib'
193             );
194              
195              
196             has 'package_shell_name' => (
197             is => 'ro',
198             isa => 'Str',
199             lazy => 1,
200             default => sub {
201             my $self = shift;
202             my $name = uc($self->zilla->name);
203             $name =~ s/-/_/g;
204             return $name;
205             }
206             );
207              
208              
209             has 'postinst_template' => (
210             is => 'ro',
211             isa => 'Str',
212             predicate => 'has_postinst_template'
213             );
214              
215              
216             has 'postinst_template_default' => (
217             is => 'ro',
218             isa => 'Str',
219             predicate => 'has_postinst_template_default'
220             );
221              
222              
223             has 'postrm_template' => (
224             is => 'ro',
225             isa => 'Str',
226             predicate => 'has_postrm_template'
227             );
228              
229              
230             has 'postrm_template_default' => (
231             is => 'ro',
232             isa => 'Str',
233             predicate => 'has_postrm_template_default'
234             );
235              
236              
237             has 'rules_template' => (
238             is => 'ro',
239             isa => 'Str',
240             predicate => 'has_rules_template'
241             );
242              
243              
244             has 'rules_template_default' => (
245             is => 'ro',
246             isa => 'Str',
247             predicate => 'has_rules_template_default'
248             );
249              
250             sub setup_installer {
251             my ($self, $arg) = @_;
252              
253             my @req_files = qw(compat control default install postinst postrm);
254             my @opt_files = qw(conffiles config init rules);
255              
256             # Now for the templates
257             my %vars = (
258             architecture => $self->architecture,
259             author => $self->zilla->authors->[0],
260             name => $self->zilla->name,
261             package_binary_depends => $self->package_binary_depends,
262             package_depends => $self->package_depends,
263             package_description => $self->package_description,
264             package_name => $self->package_name,
265             package_priority=> $self->package_priority,
266             package_section => $self->package_section,
267             package_shell_name => $self->package_shell_name,
268             version => $self->zilla->version
269             );
270            
271             foreach my $file (@req_files) {
272             $self->_generate_file($file, 1, { %vars });
273             }
274             foreach my $file (@opt_files) {
275             $self->_generate_file($file, 0, { %vars });
276             }
277             }
278              
279             sub _generate_file {
280             my ($self, $file, $required, $vars) = @_;
281              
282             my $pred = 'has_'.$file.'_template';
283             my $temp = $file.'_template';
284             my $pred_def = 'has_'.$file.'_template_default';
285             my $def = $file.'_template_default';
286              
287             my $template;
288             if($self->$pred) {
289             # We have a template, use it.
290             die "Can't find file: ".$self->$temp unless -e $self->$temp;
291             $template = Text::Template->new(TYPE => 'FILE', SOURCE => $self->$temp);
292             $self->log("Used template for file '$file'");
293             } elsif($self->$pred_def) {
294             # We have a default, use it
295             $template = Text::Template->new(TYPE => 'STRING', SOURCE => $self->$def);
296             $self->log("Used default for file '$file'");
297             } else {
298             # Blow up, we ain't got shit
299             $self->log("No template or default for '$file'");
300             if($required) {
301             die "No template or default provided for '$file'";
302             }
303             }
304              
305             if(defined($template)) {
306             $self->log("Added file for '$file'");
307             $self->add_file(Dist::Zilla::File::InMemory->new({
308             content => $template->fill_in(HASH => $vars),
309             name => "debian/$file"
310             }));
311             }
312             }
313              
314             1;
315              
316             __END__
317             =pod
318              
319             =head1 NAME
320              
321             Dist::Zilla::Plugin::Dpkg - Generate Dpkg files for your perl module
322              
323             =head1 VERSION
324              
325             version 0.05
326              
327             =head1 SYNOPSIS
328              
329             # [Dpkg]
330             # architecture = amd64
331             # default_template = package/debian/default
332              
333             =head1 DESCRIPTION
334              
335             Dist::Zilla::Plugin::Dpkg generates Debian' controls files that you can use
336             with debhelper to generate packages of your perl module.
337              
338             There are a handful of tools that provide similar functionality. Most of
339             them expect your perl module to have a standard installation mechanism. This
340             module was born of a need for customization. It's projects used per-package
341             perlbrews and all manner of custom bits.
342              
343             =head1 TEMPLATES
344              
345             This plugin uses L<Text::Template>. The following variables will be passed
346             to any templates that are processed, using attributes as values:
347              
348             =over 4
349              
350             =item architecture
351              
352             =item author (first in authors list)
353              
354             =item name
355              
356             =item package_binary_depends
357              
358             =item package_depends
359              
360             =item package_description
361              
362             =item package_name
363              
364             =item package_section
365              
366             =item package_shell_name
367              
368             =item version
369              
370             =back
371              
372             =head1 SUBCLASSING
373              
374             Each of the aforementioned template methods has an accompanying method that
375             provides a default template. Most of these are undefined and therefore
376             unused. This subclassing behavior allows you to create subclasses of
377             Dist::Zilla::Plugin::Dpkg that provide default templates for many of the files.
378              
379             The idea is to allow the easy creation of something like a
380             Dist::Zilla::Plugin::Dpkg::Starman that provides boilerplate code for a
381             L<Starman>-based application.
382              
383             =head1 ATTRIBUTES
384              
385             =head2 architecture
386              
387             The architecture of the package we're building. Defaults to C<any>.
388              
389             =head2 compat_template
390              
391             If set, the specified file is used as a template for the C<compat> file.
392              
393             =head2 compat_template_default
394              
395             A default compat file template that will be used it a template isn't provided
396             to C<compat_template>.
397              
398             =head2 conffiles_template
399              
400             If set, the specified file is used as a template for the C<conffiles> file.
401              
402             =head2 conffiles_template_default
403              
404             A default conffiles file template that will be used it a template isn't
405             provided to C<conffiles_template>.
406              
407             =head2 config_template
408              
409             If set, the specified file is used as a template for the C<config> file.
410              
411             =head2 config_template_default
412              
413             A default config file template that will be used it a template isn't provided
414             to C<config_template>.
415              
416             =head2 control_template
417              
418             If set, the specified file is used as a template for the C<control> file.
419             If not set uses an internal default.
420              
421             =head2 control_template_default
422              
423             A default control file template that will be used it a template isn't provided
424             to C<control_template>.
425              
426             =head2 default_template
427              
428             If set, the specified file is used as a template for the C<default> file.
429              
430             =head2 default_template_default
431              
432             A default default file template that will be used it a template isn't provided
433             to C<default_template>.
434              
435             =head2 init_template
436              
437             If set, the specified file is used as a template for the C<init> file.
438              
439             =head2 init_template_default
440              
441             A default init file template that will be used it a template isn't provided
442             to C<init_template>.
443              
444             =head2 install_template
445              
446             If set, the specified file is used as a template for the C<install> file.
447              
448             =head2 install_template_default
449              
450             A default install file template that will be used it a template isn't provided
451             to C<install_template>.
452              
453             =head2 package_depends
454              
455             Source binary dependencies. Defaults to C<debhelper (>= 7.0.50~)>.
456              
457             http://www.debian.org/doc/debian-policy/ch-relationships.html#s-sourcebinarydeps
458              
459             =head2 package_binary_depends
460              
461             Binary dependencies. Defaults to <C${misc:Depends}, ${shlibs:Depends}, ${perl:Depends}>.
462              
463             http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps
464              
465             =head2 package_description
466              
467             The description of the package we're making. Should use the form of:
468              
469             Synopsis
470             Multi-line description
471             tacked on the end
472              
473             L<http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Description>.
474              
475             =head2 package_name
476              
477             The name of the package we're making. Defaults to the lowercased version of
478             the package name. Uses Dist::Zilla's C<name> attribute.
479              
480             =head2 package_priority
481              
482             The priority of the package we're making. Defaults to C<extra>.
483              
484             L<http://www.debian.org/doc/debian-policy/ch-archive.html#s-priorities>.
485              
486             =head2
487              
488             The section of the package we're making. Defaults to C<lib>.
489              
490             L<http://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections>.
491              
492             =head2 package_shell_name
493              
494             The name of this package converted to a form suitable for environment variable
495             use. Foo-Bar becomes FOO_BAR. Defaults to C<name> upper-cased with hyphens
496             converted to underscores.
497              
498             =head2 postinst_template
499              
500             If set, the specified file is used as a template for the C<postinst> file.
501              
502             =head2 postinst_template_default
503              
504             A default postinst file template that will be used it a template isn't provided
505             to C<postinst_template>.
506              
507             =head2 postrm_template
508              
509             If set, the specified file is used as a template for the C<postrm> file.
510              
511             =head2 postrm_template_default
512              
513             A default postrm file template that will be used it a template isn't provided
514             to C<postrm_template>.
515              
516             =head2 rules_template
517              
518             If set, the specified file is used as a template for the C<rules> file.
519              
520             =head2 rules_template_default
521              
522             A default rules file template that will be used it a template isn't provided
523             to C<rules_template>.
524              
525             =head1 METHODS
526              
527             =head2 has_compat_template
528              
529             =head2 has_compat_template_default
530              
531             =head2 has_conffiles_template
532              
533             Predicate that is true if there is a conffiles_template
534              
535             =head2 has_conffiles_template_template
536              
537             =head2 has_config_template
538              
539             =head2 has_config_template_default
540              
541             =head2 has_control_template
542              
543             =head2 has_control_template_default
544              
545             =head2 has_default_template
546              
547             =head2 has_default_template_default
548              
549             =head2 has_init_template
550              
551             =head2 has_init_template_default
552              
553             =head2 has_install_template
554              
555             =head2 has_install_template_default
556              
557             =head2 has_postinst_template
558              
559             =head2 has_postinst_template_default
560              
561             =head2 has_postrm_template
562              
563             =head2 has_postrm_template_default
564              
565             =head2 has_rules_template
566              
567             =head2 has_rules_template_default
568              
569             =head1 AUTHOR
570              
571             Cory G Watson <gphat@cpan.org>
572              
573             =head1 COPYRIGHT AND LICENSE
574              
575             This software is copyright (c) 2013 by Infinity Interactive, Inc.
576              
577             This is free software; you can redistribute it and/or modify it under
578             the same terms as the Perl 5 programming language system itself.
579              
580             =cut
581