Skip to content

Commit

Permalink
dzil listdeps --json command
Browse files Browse the repository at this point in the history
Conflicts:
	Changes
  • Loading branch information
karenetheridge authored and rjbs committed Mar 18, 2013
1 parent e64b618 commit e90f5a2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
5 changes: 4 additions & 1 deletion Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ Revision history for {{$dist->name}}

{{$NEXT}}
stacktrace removed from exception when a plugin's minimum version
check fails
check fails (thanks, Karen Etheridge!)

add 'dzil listdeps --json', which lists all prerequisites broken up
by phase and type, in readable JSON format (thanks, Karen Etheridge!)

4.300030 2013-01-30 22:25:27 America/New_York
listdeps --versions now sorts properly (thanks, Karen Etheridge!)
Expand Down
30 changes: 26 additions & 4 deletions lib/Dist/Zilla/App/Command/listdeps.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ List only dependencies which are unsatisfied.
Also display the required versions of listed modules.
=head2 --json
Lists all prerequisites in JSON format, as they would appear in META.json
(broken out into phases and types)
=head1 ACKNOWLEDGEMENTS
This code was originally more or less a direct copy of Marcel Gruenauer (hanekomu)
Expand All @@ -44,21 +49,29 @@ sub abstract { "print your distribution's prerequisites" }
sub opt_spec {
[ 'author', 'include author dependencies' ],
[ 'missing', 'list only the missing dependencies' ],
[ 'versions', 'include required version numbers in listing' ]
[ 'versions', 'include required version numbers in listing' ],
[ 'json', 'list dependencies by phase, in JSON format' ],
}

sub extract_dependencies {
my ($self, $zilla, $phases, $missing) = @_;
sub prereqs {
my ($self, $zilla) = @_;

$_->before_build for @{ $zilla->plugins_with(-BeforeBuild) };
$_->gather_files for @{ $zilla->plugins_with(-FileGatherer) };
$_->prune_files for @{ $zilla->plugins_with(-FilePruner) };
$_->munge_files for @{ $zilla->plugins_with(-FileMunger) };
$_->register_prereqs for @{ $zilla->plugins_with(-PrereqSource) };

my $prereqs = $zilla->prereqs;
}

sub extract_dependencies {
my ($self, $zilla, $phases, $missing) = @_;

my $prereqs = $self->prereqs($zilla);

require CPAN::Meta::Requirements;
my $req = CPAN::Meta::Requirements->new;
my $prereqs = $zilla->prereqs;

for my $phase (@$phases) {
$req->add_requirements( $prereqs->requirements_for($phase, 'requires') );
Expand Down Expand Up @@ -95,6 +108,15 @@ sub execute {
my @phases = qw(build test configure runtime);
push @phases, 'develop' if $opt->author;

if($opt->json) {
my $prereqs = $self->prereqs($self->zilla);
my $output = $prereqs->as_string_hash;

require JSON; JSON->VERSION(2);
print JSON->new->ascii(1)->canonical(1)->pretty->encode($output), "\n";
return 1;
}

my %modules = $self->extract_dependencies($self->zilla, \@phases, $opt->missing);

if($opt->versions) {
Expand Down

0 comments on commit e90f5a2

Please sign in to comment.