Skip to content

Commit

Permalink
Loads more fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
bingos committed Jun 17, 2010
1 parent 6263aa3 commit 4abe911
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 10 deletions.
28 changes: 22 additions & 6 deletions bin/dzooky
Expand Up @@ -3,26 +3,42 @@ package dzooky;
use strict;
use warnings;
use Dist::Zooky::App;
# ABSTRACT: do stuff with your dist
# ABSTRACT: convert a dist to Dist::Zilla
Dist::Zooky::App->run;

=pod

=head1 NAME

dzooky - convert a dist to Dist::Zilla

=head1 SYNOPSIS

$ cd Some-Dist-Dir
$ dzooky

=head1 DESCRIPTION

dzooky is a L<Dist::Zilla>'s nephew. He has the ability to summon his uncle.
dzooky is L<Dist::Zilla>'s nephew. He has the ability to summon his uncle.

dzooky will try its best to convert a distribution to use L<Dist::Zilla>. It
suuports L<ExtUtils::MakeMaker>, L<Module::Install> and L<Module::Build> based
distributions, with certain limitations.

Simply execute C<dzooky> in the directory containing the distribution you wish
to convert to L<Dist::Zilla>. C<dzooky> will determine the type of distribution
it is and execute the C<Makefile.PL> or C<Build.PL> and gather meta information
to generate a C<dist.ini> file for you.

It will C<die> on any error conditions it encounters.

=head1 CAVEAT PROGRAMMER

This should be considered as experimental for the moment. It does work in the main
but there are some C<gotchas>.

The L<ExtUtils::MakeMaker> examination is done by parsing the C<Makefile> that is
produced by executing C<Makefile.PL>. L<Module::Install> will also fall back to
this mechanism if a C<MYMETA.yml> file is not generated.

The L<Module::Build> examination is purely from C<MYMETA.yml>.

This has some limitations.

=cut
20 changes: 19 additions & 1 deletion lib/Dist/Zooky.pm
Expand Up @@ -10,13 +10,19 @@ use MooseX::Types::Perl qw(DistName LaxVersionStr);
use Dist::Zooky::License;
use Dist::Zooky::DistIni;
use Module::Pluggable search_path => 'Dist::Zooky::Core';
use ExtUtils::MakeMaker ();

has name => (
is => 'ro',
isa => DistName,
writer => 'set_name',
);

has 'make' => (
is => 'ro',
isa => 'Str',
);

sub examine {
my $self = shift;

Expand Down Expand Up @@ -47,7 +53,7 @@ sub examine {
foreach my $plugin ( $self->plugins ) {
if ( $plugin =~ /$type$/ ) {
Class::MOP::load_class( $plugin );
$core = $plugin->new();
$core = $plugin->new( ( $type eq 'MakeMaker' and $self->make ? ( make => $self->make ) : () ) );
}
}

Expand All @@ -70,6 +76,18 @@ sub examine {

my $ini = Dist::Zooky::DistIni->new( metadata => $meta );
$ini->write;

warn "Wrote 'dist.ini'\n";

my @files = grep { -e $_ } qw(MANIFEST Makefile.PL Build.PL);
my $prompt = "\nThere are a number of files that should be removed now\n\n" .
"Do you want me to remove [" . join(' ', @files ) . "] ? (yes/no)";
my $answer = ExtUtils::MakeMaker::prompt($prompt, 'no');
if ($answer =~ /\A(?:y|ye|yes)\z/i) {
warn "Removing files\n";
unlink $_ for @files;
}
warn "Done.\n";
}

__PACKAGE__->meta->make_immutable;
Expand Down
1 change: 1 addition & 0 deletions lib/Dist/Zooky/App.pm
Expand Up @@ -9,3 +9,4 @@ use App::Cmd::Setup 0.307 -app;
sub default_command { 'dist' }

qq[Meep];

28 changes: 27 additions & 1 deletion lib/Dist/Zooky/App/Command/dist.pm
@@ -1,18 +1,44 @@
package Dist::Zooky::App::Command::dist;

# ABSTRACT: The one command that Dist::Zooky uses

use strict;
use warnings;
use Dist::Zooky::App -command;

sub abstract { 'Dist::Zooky!' }

sub opt_spec {
return (
[ 'make=s', 'Specify make utility to use', ],
);
}

sub execute {
my ($self, $opt, $args) = @_;
require Dist::Zooky;
my $zooky = Dist::Zooky->new();
my $zooky = Dist::Zooky->new( ( defined $opt->{make} ? ( make => $opt->{make} ) : () ) );
$zooky->examine;
return;
}

qq[Lighten up and play];

=pod
=head1 DESCRIPTION
Dist::Zooky has but one command, this is it. And it is the default so
you should never need to specify it.
=head1 METHOD
=over
=item C<execute>
This runs L<Dist::Zooky> for you.
=back
=cut
1 change: 1 addition & 0 deletions lib/Dist/Zooky/Core/MakeMaker.pm
Expand Up @@ -18,6 +18,7 @@ sub examine {
my $self = shift;

{
local $ENV{X_MYMETA} = 1; # Make Module::Install produce MYMETA.yml
local $ENV{PERL_MM_USE_DEFAULT} = 1;
local $ENV{PERL_EXTUTILS_AUTOINSTALL} = '--defaultdeps';

Expand Down
54 changes: 54 additions & 0 deletions lib/Dist/Zooky/Core/ModBuild.pm
@@ -0,0 +1,54 @@
package Dist::Zooky::Core::ModBuild;

use strict;
use warnings;
use Moose;
use IPC::Cmd qw[run can_run];

with 'Dist::Zooky::Role::Core';
with 'Dist::Zooky::Role::Meta';

sub examine {
my $self = shift;

{
local $ENV{PERL_MM_USE_DEFAULT} = 1;

my $cmd = [ $^X, 'Build.PL' ];
run ( command => $cmd, verbose => 0 );
}

if ( -e 'MYMETA.yml' ) {

my $struct = $self->meta_from_file( 'MYMETA.yml' );
$self->_set_name( $struct->{name} );
$self->_set_author( $struct->{author} );
$self->_set_license( $struct->{license} );
$self->_set_version( $struct->{version} );
$self->_set_prereqs( $struct->{prereqs} );

}
else {

die "Couldn\'t find a 'MYMETA.yml' file, giving up\n";

}

{
my $cmd = [ $^X, 'Build', 'distclean' ];
run( command => $cmd, verbose => 0 );
}

return;
}

sub return_meta {
my $self = shift;
return { map { ( $_, $self->$_ ) } qw(author name version license Prereq) };
}

__PACKAGE__->meta->make_immutable;
no Moose;

qq[MakeMaker];

13 changes: 11 additions & 2 deletions lib/Dist/Zooky/DistIni.pm
Expand Up @@ -13,7 +13,7 @@ name = {{ $name }}
version = {{ $version }}
{{ $OUT .= join "\n", map { "author = $_" } @authors; }}
{{ $OUT .= join "\n", map { "license = $_" } @licenses; }}
{{ ( my $holder = $authors[0] ) =~ s/\s*\<.+?\>\s*//g; "holder = $holder"; }}
{{ ( my $holder = $authors[0] ) =~ s/\s*\<.+?\>\s*//g; "copyright_holder = $holder"; }}
[GatherDir]
[PruneCruft]
Expand Down Expand Up @@ -42,18 +42,27 @@ version = {{ $version }}
$OUT .= "[Prereq / ConfigureRequires]\n";
$OUT .= join(' = ', $_, $configure{$_}) . "\n" for sort keys %configure;
}
else {
$OUT .= ';[Prereq / ConfigureRequires]';
}
}}
{{
if ( keys %build ) {
$OUT .= "[Prereq / BuildRequires]\n";
$OUT .= join(' = ', $_, $build{$_}) . "\n" for sort keys %build;
}
else {
$OUT .= ';[Prereq / BuildRequires]';
}
}}
{{
if ( keys %runtime ) {
$OUT .= "[Prereq]\n";
$OUT .= join(' = ', $_, $runtime{$_}) . "\n" for sort keys %runtime;
}
else {
$OUT .= ';[Prereq]';
}
}}
|;

Expand All @@ -69,7 +78,7 @@ sub write {
my %stash;
$stash{$_} = $self->metadata->{Prereq}->{$_}->{requires}
for qw(configure build runtime);
$stash{$_} = $self->metadata->{$_} for qw(author license version name);
$stash{$_} = $self->metadata->{$_} for qw(author license version name type);
$stash{"${_}s"} = delete $stash{$_} for qw(author license);
my $content = $self->fill_in_string(
$template,
Expand Down
33 changes: 33 additions & 0 deletions t/02_distini.t
Expand Up @@ -25,4 +25,37 @@ use_ok('Dist::Zooky::DistIni');
$distini->write( $file );

ok( -e $file, 'The file exists' );

{
open my $fh, '<', $file or die "Could not open '$file': $!\n";
my $content = do { local $/; <$fh> };

like( $content, qr/\Q$_\E/s, "Content contains '$_'" ) for
( 'name = Foo-Bar',
'version = 0.02',
'author = Duck Dodgers',
'author = Ivor Module',
'license = Perl_5',
'holder = Duck Dodgers',
'[GatherDir]',
'[PruneCruft]',
'[ManifestSkip]',
'[MetaYAML]',
'[MetaJSON]',
'[License]',
';[Readme]',
'[ExecDir]',
'[ExtraTests]',
'[ShareDir]',
'[MakeMaker]',
'[Manifest]',
'[TestRelease]',
'[ConfirmRelease]',
'[UploadToCPAN]',
';[Prereq / ConfigureRequires]',
';[Prereq / BuildRequires]',
';[Prereq]',);

close $fh;
}
}

0 comments on commit 4abe911

Please sign in to comment.