App-TaskBuilder

 view release on metacpan or  search on metacpan

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

use strict;
use warnings;

package App::TaskBuilder;
our $VERSION = '1.000';

use File::Spec;
use File::Path ();
use File::Basename ();
use File::Temp ();
use File::Copy ();
use Cwd ();

sub _accessor {
  no strict 'refs';
  my $attr = shift;
  *$attr = sub { @_ > 1 ? ($_[0]->{$attr} = $_[1]) : $_[0]->{$attr} };
}
BEGIN { _accessor($_) for qw(name require include version output) }

sub new {
  my $class = shift;
  my $self = bless {@_} => $class;
  $self->{output} ||= $self->vars->{dist_vname} . ".tar.gz";
  %{ $self->require } = (
    (map {
      my %r = %{ do($_) || die $@ };
      ( 
        %{ $r{requires} || {} },
        %{ $r{test_requires} || {} },
        %{ $r{build_requires} || {} },
      );
    } @{ $self->include }),
    %{ $self->require }
  );
  return $self;
}

sub _dist_name {
  my ($self) = @_;
  (my $name = $self->name) =~ s/::/-/g;
  $name;
}

sub _file_name {
  my ($self) = @_;
  my @parts = split /::/, ($self->name . '.pm');
  File::Spec->catfile('lib', @parts);
}

sub vars {
  my $self = shift;
  use Data::Dumper;
  local $Data::Dumper::Terse = 1;
  my %v = (
    mod_name  => $self->name,
    dist_name => $self->_dist_name,
    mod_file  => $self->_file_name,
    requires  => Dumper($self->require),
    version   => $self->version,
  );
  $v{dist_vname} = "$v{dist_name}-$v{version}";
  return wantarray ? %v : \%v;
}

sub run {
  my $self = shift;
  my $old = Cwd::cwd;
  chdir(my $tmp = File::Temp::tempdir(CLEANUP => 1));

  my %v = $self->vars; 
  mkdir $v{dist_vname}, 0755 or die "Can't mkdir $v{dist_vname}: $!";

  my $s = $self->templates(%v);

  for my $path (keys %$s) {
    my $text = $s->{$path};
    $path = "$v{dist_vname}/$path";
    File::Path::mkpath(File::Basename::dirname($path));
    open my $fh, '>', $path or die "Can't open $path: $!";
    $text =~ s/\{\{(.+?)\}\}/$v{$1}/g;
    print $fh $text;
  }

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.026 second using v1.00-cache-1.14-grep-28634ff-cpan-4d46879620f )