App-podweaver

 view release on metacpan or  search on metacpan

lib/App/podweaver.pm  view on Meta::CPAN

        unless( $licenses{ $license } )
        {
            $log->errorf( "Unknown license: '%s'", $license )
                if $log->is_error();
            return;
        }

        $license = $licenses{ $license };

        my $class = "Software::License::$license";
        unless( eval "use $class; 1" )
        {
            $log->errorf( "Can't load Software::License::$license: %s", $@ )
                if $log->is_error();
            return;
        }

        $dist_info->{ license } = $class->new( {
            holder => join( ' & ', @{$dist_info->{ authors }} ),
            } );

        $log->debugf( "Using license: '%s'", $dist_info->{ license }->name() )
            if $log->is_debug();

        $dist_info->{ dist_version } = $dist_info->{ meta }->version();
    }

    return( $dist_info );
}

sub get_weaver
{
    my ( $self, %options ) = @_;
    my ( $dist_root, $config_file );

    $dist_root = $options{ dist_root } || '.';    
    if( -r ( $config_file = File::Spec->catfile( $dist_root, 'weaver.ini' ) ) )
    {
        $log->debug( "Initializing weaver from ./weaver.ini" )
            if $log->is_debug();
        return( Pod::Weaver->new_from_config( {
            root => $dist_root,
            } ) );
    }
    $log->warningf( "No '%s' found, using Pod::Weaver defaults, " .
        "this will most likely insert duplicate sections",
        $config_file )
        if $log->is_warning();
    return( Pod::Weaver->new_with_default_config() );
}

sub find_files_to_weave
{
    my ( $self, %options ) = @_;
    my ( $dist_root );

    $dist_root = $options{ dist_root } || '.';    

    return(
        File::Find::Rule->ignore_vcs
                        ->not_name( qr/~$/ )
                        ->perl_file
                        ->in(
                            grep { -d $_ }
                            map  { File::Spec->catfile( $dist_root, $_ ) }
                            qw/lib bin script/
                            )
        );
}

sub weave_distribution
{
    my ( $self, %options ) = @_;
    my ( $weaver, $dist_info );

    $dist_info = $self->get_dist_info( %options );
    $weaver    = $self->get_weaver( %options );

    foreach my $file ( $self->find_files_to_weave() )
    {
        $log->noticef( "Weaving file '%s'", $file )
            if $log->is_notice();

        $self->weave_file(
            %options,
            %{$dist_info},
            filename => $file,
            weaver   => $weaver,
            );
    }
}

sub _config_dir
{
    my ( $self ) = @_;
    my ( $leaf_dir, $config_dir );

    #  Following lifted from File::UserDir.
    #  I'd use that directly but it forces creation and population of the dir.

    # Derive from the caller based on HomeDir naming scheme
    my $scheme = $File::HomeDir::IMPLEMENTED_BY or
        die "Failed to find File::HomeDir naming scheme";
    if( $scheme->isa( 'File::HomeDir::Darwin' ) or
        $scheme->isa( 'File::HomeDir::Windows' ) )
    {
        $leaf_dir = 'App-podweaver';
    }
    elsif( $scheme->isa('File::HomeDir::Unix') )
    {
        $leaf_dir = '.app-podweaver';
    }
    else
    {
        die "Unsupported HomeDir naming scheme $scheme";
    }

    $config_dir = File::Spec->catdir(
        File::HomeDir->my_data(),
        $leaf_dir
        );



( run in 1.231 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )