CatalystX-Starter

 view release on metacpan or  search on metacpan

lib/CatalystX/Starter.pm  view on Meta::CPAN

# Copyright (c) 2007 Jonathan Rockway <jrockway@cpan.org>

package CatalystX::Starter;
use strict;
use warnings;

our $VERSION = '0.07';

use File::ShareDir qw/module_dir/;
use File::Copy::Recursive qw/dircopy/;
use File::Slurp qw/read_file write_file/;
use File::pushd;

# don't use any of these subroutines.

sub _boilerplate {
    return module_dir('CatalystX::Starter');
}

sub _module2dist {
    my $module = shift;
    die("You seem to have passed a dist name, not a module name: $module\n")
        unless $module =~ /::/;
    $module =~ s/::/-/g;
    return $module;
}

sub _copy_files {
    my $dest = shift;
    my $src  = _boilerplate();
    dircopy($src, $dest) or die "Failed to install boilerplate: $!";
}

sub _fix_files {
    my ($module, $dir) = @_;
    
    opendir my $dh, $dir or die "Failed to opendir $dir: $!";
    my @paths = grep {!/^[.][.]?$/} readdir $dh 
      or die "Failed to read $dir: $!";

    my $p = pushd $dir;
    my @dirs  = grep { -d  } @paths;
    my @files = grep { !-d } @paths;

    # fix files
    {
        my $dist_name = $module;
        my $main_module_path = "lib/$module.pm";
        $dist_name =~ s/::/-/g;
        $main_module_path =~ s|::|/|g;

        foreach my $file (@files) {
            my $data = read_file($file);
            chmod 0644, $file;
            $data =~ s/\[% DIST_NAME %\]/$dist_name/g;
            $data =~ s/\[% MODULE %\]/$module/g;
            $data =~ s/\[% MAIN_MODULE_PATH %\]/$main_module_path/g;
            write_file($file, $data);
        }
    }
    # fix subdirs
    _fix_files($module, $_) for @dirs;
    closedir $dh;
    
    return;
}

sub _split_module {
    my $module = shift;
    return split /::/, $module;
}

sub _mk_module {
    my $module = shift;
    my $dist   = shift;
    
    my $d = pushd $dist;
    mkdir 'lib';
    die "Failed to create lib in $dist: $!" unless -d 'lib';

    chdir 'lib';
    my @path = _split_module($module);
    my $file = pop @path;
    foreach my $part (@path) {
        mkdir $part;
        die "Failed to mkdir $part: $!" if !-d $part;
        chdir $part;
    }
    
    my $data = <<"MOD"; # indented to prevent pod parser from parsing it
 package $module;
 use Moose;
 use namespace::autoclean;
 
 1;
 
 =head1 NAME
 
 $module - 
 
 =head1 DESCRIPTION
 
 =head1 METHODS
 
 =head1 BUGS
 
 =head1 AUTHOR
 
 =head1 COPYRIGHT & LICENSE

 Copyright 2009 the above author(s).
 
 This sofware is free software, and is licensed under the same terms as perl itself.
 



( run in 2.106 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )