File Coverage

lib/CPANPLUS/Dist/PAR.pm
Criterion Covered Total %
statement 40 50 80.0
branch 4 16 25.0
condition 2 6 33.3
subroutine 10 10 100.0
pod 2 2 100.0
total 58 84 69.0


line stmt bran cond sub pod time code
1             package CPANPLUS::Dist::PAR;
2 3     3   616568 use strict;
  3         6  
  3         125  
3              
4 3     3   16 use vars qw[@ISA $VERSION];
  3         5  
  3         186  
5 3     3   39 use base 'CPANPLUS::Dist::Base';
  3         6  
  3         3924  
6              
7 3     3   415893 use CPANPLUS::Error;
  3         8  
  3         242  
8 3     3   19 use File::Basename qw[basename];
  3         5  
  3         175  
9 3     3   17 use Params::Check qw[check];
  3         6  
  3         125  
10 3     3   26 use Module::Load::Conditional qw[can_load];
  3         6  
  3         146  
11 3     3   17 use Locale::Maketext::Simple Class => 'CPANPLUS', Style => 'gettext';
  3         6  
  3         32  
12              
13             $VERSION = '0.02';
14              
15             local $Params::Check::VERBOSE = 1;
16              
17             =head1 NAME
18              
19             CPANPLUS::Dist::PAR - CPANPLUS distribution class to create PAR archives
20              
21             =head1 SYNOPSIS
22              
23             use CPANPLUS::Backend;
24            
25             my $cb = CPANPLUS::Backend->new;
26             my $mod = $cb->module_tree('Some::Module');
27            
28             $mod->test( format => 'CPANPLUS::Dist::PAR' );
29              
30             =head1 DESCRIPTION
31              
32             Creates a C distribution of a CPAN module, using the
33             C plugin structure.
34              
35             See the C manpage how to pass formats to the install
36             methods.
37              
38             See the C manpage for details about the generated archives.
39              
40             =cut
41              
42             ### we can't install things withour our dependencies.
43             sub format_available {
44 6 50   6 1 22768176 return unless can_load( modules => {
45             'PAR::Dist' => 0
46             } );
47 6         50562 return 1;
48             }
49              
50             sub create {
51             ### just in case you already did a create call for this module object
52             ### just via a different dist object
53 1     1 1 1237822 my $dist = shift;
54 1         15 my $self = $dist->parent;
55 1         145 my $dist_cpan = $self->status->dist_cpan;
56 1 50       87 $dist = $self->status->dist if $self->status->dist;
57 1 50       172 $self->status->dist( $dist ) unless $self->status->dist;
58              
59 1         101 my $cb = $self->parent;
60 1         36 my $conf = $cb->configure_object;
61            
62 1 50       32 $dist->SUPER::create( @_ ) or return;
63            
64 1         3959993 msg( loc("Creating PAR dist of '%1'", $self->name), 1);
65              
66             ### par::dist is noisy, silence it
67             ### XXX this doesn't quite work -- restoring STDOUT still has
68             ### it closed
69             #*STDOUT_SAVE = *STDOUT; close *STDOUT;
70 1         1645 my $par = eval {
71             ### pass name and version explicitly, as parsing doesn't always
72             ### work
73 1         38 PAR::Dist::blib_to_par(
74             path => $self->status->extract,
75             version => $self->package_version,
76             name => $self->package_name,
77             );
78             };
79            
80             ### error?
81 1 0 33     76803 if( $@ or not $par or not -e $par ) {
      33        
82 1         38 error(loc("Could not create PAR distribution of %1: %2",
83             $self->name, $@ ));
84 1         5601 return;
85             }
86              
87 0           my ($to,$fail);
88 0           MOVE: {
89 0           my $dir = File::Spec->catdir(
90             $conf->get_conf('base'),
91             CPANPLUS::Internals::Utils
92             ->_perl_version(perl => $^X),
93             $conf->_get_build('distdir'),
94             'PAR'
95             );
96 0           my $to = File::Spec->catfile( $dir, basename($par) );
97              
98 0 0         $cb->_mkdir( dir => $dir ) or $fail++, last MOVE;
99 0 0         $cb->_move( file => $par, to => $to ) or $fail++, last MOVE;
100 0           msg(loc("PAR distribution written to: '%1'", $to), 1);
101            
102 0           $dist->status->dist( $to );
103             }
104            
105 0 0         return $dist->status->created(1) unless $fail;
106 0           return;
107             }
108              
109             =head1 AUTHOR
110              
111             This module by
112             Jos Boumans Ekane@cpan.orgE.
113              
114             =head1 COPYRIGHT
115              
116             This module is copyright (c) 2006 Jos Boumans .
117             All rights reserved.
118              
119             This library is free software; you may redistribute and/or modify
120             it under the same terms as Perl itself.
121              
122             =head1 SEE ALSO
123              
124             L, L, L,
125             C, C
126              
127             =cut
128              
129             # Local variables:
130             # c-indentation-style: bsd
131             # c-basic-offset: 4
132             # indent-tabs-mode: nil
133             # End:
134             # vim: expandtab shiftwidth=4:
135              
136             1;