CPANPLUS::Dist::PAR - CPANPLUS distribution class to create PAR archives


CPANPLUS-Dist-PAR documentation Contained in the CPANPLUS-Dist-PAR distribution.

Index


Code Index:

NAME

Top

CPANPLUS::Dist::PAR - CPANPLUS distribution class to create PAR archives

SYNOPSIS

Top

    use CPANPLUS::Backend;

    my $cb  = CPANPLUS::Backend->new;
    my $mod = $cb->module_tree('Some::Module');

    $mod->test( format => 'CPANPLUS::Dist::PAR' );

DESCRIPTION

Top

Creates a PAR distribution of a CPAN module, using the CPANPLUS::Dist::* plugin structure.

See the CPANPLUS::Module manpage how to pass formats to the install methods.

See the PAR::Dist manpage for details about the generated archives.

AUTHOR

Top

This module by Jos Boumans <kane@cpan.org>.

COPYRIGHT

Top

SEE ALSO

Top

CPANPLUS::Backend, CPANPLUS::Module, CPANPLUS::Dist, cpan2dist, PAR::Dist


CPANPLUS-Dist-PAR documentation Contained in the CPANPLUS-Dist-PAR distribution.
package CPANPLUS::Dist::PAR;
use strict;

use vars    qw[@ISA $VERSION];
use base    'CPANPLUS::Dist::Base';

use CPANPLUS::Error;
use File::Basename              qw[basename];
use Params::Check               qw[check];
use Module::Load::Conditional   qw[can_load];
use Locale::Maketext::Simple    Class => 'CPANPLUS', Style => 'gettext';

$VERSION =  '0.02';

local $Params::Check::VERBOSE = 1;

### we can't install things withour our dependencies.
sub format_available { 
    return unless can_load( modules => {
                            'PAR::Dist' => 0 
                        } );
    return 1;
}

sub create { 
    ### just in case you already did a create call for this module object
    ### just via a different dist object
    my $dist        = shift;
    my $self        = $dist->parent;
    my $dist_cpan   = $self->status->dist_cpan;
    $dist           = $self->status->dist   if      $self->status->dist;
    $self->status->dist( $dist )            unless  $self->status->dist;

    my $cb   = $self->parent;
    my $conf = $cb->configure_object;
    
    $dist->SUPER::create( @_ ) or return;
    
    msg( loc("Creating PAR dist of '%1'", $self->name), 1);

    ### par::dist is noisy, silence it
    ### XXX this doesn't quite work -- restoring STDOUT still has
    ### it closed
    #*STDOUT_SAVE = *STDOUT; close *STDOUT;
    my $par = eval {
        ### pass name and version explicitly, as parsing doesn't always
        ### work
        PAR::Dist::blib_to_par( 
            path    => $self->status->extract,
             version => $self->package_version,
             name    => $self->package_name,
        );
    };          
    
    ### error?
    if( $@ or not $par or not -e $par ) {
        error(loc("Could not create PAR distribution of %1: %2",
                  $self->name, $@ ));
        return;                  
    }

    my ($to,$fail);
    MOVE: {
        my $dir = File::Spec->catdir(
                        $conf->get_conf('base'),
                        CPANPLUS::Internals::Utils
                           ->_perl_version(perl => $^X),
                        $conf->_get_build('distdir'),
                        'PAR'
                    );      
        my $to  = File::Spec->catfile( $dir, basename($par) );

        $cb->_mkdir( dir => $dir )              or $fail++, last MOVE;                     
        $cb->_move( file => $par, to => $to )   or $fail++, last MOVE;                     
        msg(loc("PAR distribution written to: '%1'", $to), 1);
    
        $dist->status->dist( $to );
    } 
    
    return $dist->status->created(1) unless $fail;
    return;
}

# Local variables:
# c-indentation-style: bsd
# c-basic-offset: 4
# indent-tabs-mode: nil
# End:
# vim: expandtab shiftwidth=4:

1;