blib/lib/Module/Install/PadrePlugin.pm

filter: Statementstmt 31.5% 12 / 38 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 4 / 7 Podpod 33.3% 1 / 3 totaltotal 30.3% 17 / 56 CC 5 SCAR 17.6
CC
5
Cov
26%
make_padre_plugin
12.0
is_padre_plugin
6.0
install_padre_plugin
6.0
CRAP 5.8
↑ Summary
1 package Module::Install::PadrePlugin;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Module::Install::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use vars qw{$VERSION @ISA};
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 $VERSION = '0.01';
9 1 @ISA = qw{Module::Install::Base};
10 }
11  
12 =head1 NAME
13  
14 Module::Install::PadrePlugin - Module::Install support for Padre plugins
15  
16 =head1 SYNOPSIS
17  
18 To add two useful "make" targets to your Padre plugin, just add the
19 C<is_padre_plugin;> line to your C<Makefile.PL>.
20  
21 use inc::Module::Install;
22
23 name 'Padre::Plugin::Foo';
24 all_from 'lib/Padre/Plugin/Foo.pm';
25
26 is_padre_plugin;
27
28 WriteAll;
29  
30 =head1 DESCRIPTION
31  
32 This module adds one directive to Module::Install
33 related to creating and installing Padre plugins as .par files and two
34 C<make> targets.
35  
36 =head2 is_padre_plugin
37  
38 If you add this directive to your C<Makefile.PL>, two new C<make> targets become
39 available to the user, see below.
40  
41 =cut
42  
43 0 ▶sub is_padre_plugin {
Subroutine is_padre_plugin: not called CC=2 SCAR=17.9
Pod documented
44 0 my ($self) = @_;
45 0 my $class = ref($self);
46 0 my $inc_class = join('::', @{$self->_top}{qw(prefix name)});
47  
48 0 my $version = $self->version;
49 0 my $distname = $self->name;
50 0 ▶ $distname =~ s/^Padre-Plugin-//
Branch: 1 branch
BranchTrueFalseTotal
$distname =~ s/^Padre-Plugin-// or die "This is not a Padre plugin The namespace doesn't start with Padre::Plugin::!" 0 0 0
51 or die "This is not a Padre plugin The namespace doesn't start with Padre::Plugin::!";
52  
53 0 my $file = $distname;
54 0 $file .= '.par';
55  
56 0 $self->postamble(<<"END_MAKEFILE");
57 # --- $class section:
58  
59 $file: all test
60 \t\$(NOECHO) \$(PERL) "-M$inc_class" -e "make_padre_plugin(q($distname),q($file),q($version))"
61  
62 plugin :: $file
63 \t\$(NOECHO) \$(NOOP)
64  
65 installplugin :: $file
66 \t\$(NOECHO) \$(PERL) "-M$inc_class" -e "install_padre_plugin(q($file))"
67  
68 END_MAKEFILE
69  
70 }
71  
72 =head1 NEW MAKE TARGETS
73  
74 =head2 plugin
75  
76 To generate a .par file from the Padre plugin at hand which
77 can be easily installed (see also below) into your Padre user
78 directory, you can simply type:
79  
80 perl Makefile.PL
81 make plugin
82  
83 Now you should have a shiny new C<FancyPlugin.par> file.
84  
85 =head2 installplugin
86  
87 To install the Padre plugin at hand as a single PAR file into your
88 Padre user/plugins directory, you can simply type:
89  
90 perl Makefile.PL
91 make installplugin
92  
93 Running C<make plugin> in between those two command isn't necessary,
94 it's run by C<installplugin> if necessary.
95  
96 =cut
97  
98 0 ▶sub make_padre_plugin {
Subroutine make_padre_plugin: not called CC=3 SCAR=24.8
Pod undocumented
99 0 my ($self, $distname, $file, $version) = @_;
100 0 ▶ unlink $file if -f $file;
Branch: 1 branch
BranchTrueFalseTotal
if -f $file 0 0 0
101  
102 0 ▶ unless ( eval { require PAR::Dist; PAR::Dist->VERSION >= 0.17 } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { require PAR::Dist; "PAR::Dist"->VERSION >= "0.17" } }) 0 0 0
103 0 warn "Please install PAR::Dist 0.17 or above first.";
104 0 return;
105 }
106  
107 0 return PAR::Dist::blib_to_par(
108 name => $distname,
109 version => $version,
110 dist => $file,
111 );
112 }
113  
114 0 ▶sub install_padre_plugin {
Subroutine install_padre_plugin: not called CC=2 SCAR=17.9
Pod undocumented
115 0 my ($self, $file) = @_;
116 0 ▶ if (not -f $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $file) 0 0 0
117 0 warn "Cannot find plugin file '$file'.";
118 0 return;
119 }
120  
121 0 require Padre;
122 0 my $plugin_dir = Padre::Config->default_plugin_dir;
123  
124 0 require File::Copy;
125 0 return File::Copy::copy($file, $plugin_dir);
126 }
127  
128 1 1;
129  
130 =head1 AUTHOR
131  
132 Steffen Mueller <smueller@cpan.org>
133  
134 =head1 COPYRIGHT AND LICENSE
135  
136 Copyright (c) 2008. Steffen Mueller
137  
138 This program is free software; you can redistribute it and/or modify it
139 under the same terms as Perl itself.
140  
141 See L<http://www.perl.com/perl/misc/Artistic.html>
142  
143 =cut
↑ Summary