| 1 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | package Module::Depends; | ||||||||||
| 3 | 1 | ▶ | use Parse::CPAN::Meta; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Cwd qw( getcwd ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use base qw( Class::Accessor::Chained ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | __PACKAGE__->mk_accessors(qw( dist_dir debug libs requires configure_requires build_requires error )); | |||||||||
| 7 | 1 | our $VERSION = '0.16'; | |||||||||
| 8 | |||||||||||
| 9 | =head1 NAME | ||||||||||
| 10 | |||||||||||
| 11 | Module::Depends - identify the dependencies of a distribution | ||||||||||
| 12 | |||||||||||
| 13 | =head1 SYNOPSIS | ||||||||||
| 14 | |||||||||||
| 15 | use YAML; | ||||||||||
| 16 | use Module::Depends; | ||||||||||
| 17 | my $deps = Module::Depends->new->dist_dir( '.' )->find_modules; | ||||||||||
| 18 | print "Our dependencies:\n", Dump $deps->requires; | ||||||||||
| 19 | |||||||||||
| 20 | =head1 DESCRIPTION | ||||||||||
| 21 | |||||||||||
| 22 | Module::Depends extracts module dependencies from an unpacked | ||||||||||
| 23 | distribution tree. | ||||||||||
| 24 | |||||||||||
| 25 | Module::Depends only evaluates the META.yml shipped with a | ||||||||||
| 26 | distribution. This won't be effective until all distributions ship | ||||||||||
| 27 | META.yml files, so we suggest you take your life in your hands and | ||||||||||
| 28 | look at Module::Depends::Intrusive. | ||||||||||
| 29 | |||||||||||
| 30 | =head1 METHODS | ||||||||||
| 31 | |||||||||||
| 32 | =head2 new | ||||||||||
| 33 | |||||||||||
| 34 | simple constructor | ||||||||||
| 35 | |||||||||||
| 36 | =cut | ||||||||||
| 37 | |||||||||||
| 38 | 12 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 39 | 12 | my $self = shift; | |||||||||
| 40 | |||||||||||
| 41 | 12 | return $self->SUPER::new({ | |||||||||
| 42 | libs => [], | ||||||||||
| 43 | requires => {}, | ||||||||||
| 44 | build_requires => {}, | ||||||||||
| 45 | configure_requires => {}, | ||||||||||
| 46 | error => '', | ||||||||||
| 47 | }); | ||||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | =head2 dist_dir | ||||||||||
| 51 | |||||||||||
| 52 | Path where the distribution has been extracted to. | ||||||||||
| 53 | |||||||||||
| 54 | =head2 find_modules | ||||||||||
| 55 | |||||||||||
| 56 | scan the C<dist_dir> to populate C<libs>, C<requires>, and C<build_requires> | ||||||||||
| 57 | |||||||||||
| 58 | =cut | ||||||||||
| 59 | |||||||||||
| 60 | 13 | ▶ | sub find_modules { | ||||||||
|
Subroutine
find_modules: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 61 | 13 | my $self = shift; | |||||||||
| 62 | |||||||||||
| 63 | 13 | my $here = getcwd; | |||||||||
| 64 | 13 | ▶ | unless (chdir $self->dist_dir) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | 1 | $self->error( "couldn't chdir to " . $self->dist_dir . ": $!" ); | |||||||||
| 66 | 1 | return $self; | |||||||||
| 67 | } | ||||||||||
| 68 | 12 | eval { $self->_find_modules }; | |||||||||
| 69 | 12 | chdir $here; | |||||||||
| 70 | 12 | ▶ | die $@ if $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | |||||||||||
| 72 | 12 | return $self; | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | 2 | ▶ | sub _find_modules { | ||||||||
|
Subroutine
_find_modules: called CC=2 SCAR=7.1
| |||||||||||
| 76 | 2 | my $self = shift; | |||||||||
| 77 | |||||||||||
| 78 | 2 | my ($file) = grep { -e $_ } qw( MYMETA.yml META.yml ); | |||||||||
| 79 | 2 | ▶ | if ($file) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | 2 | my $meta = ( Parse::CPAN::Meta::LoadFile( $file ) )[0]; | |||||||||
| 81 | 2 | $self->requires( $meta->{requires} ); | |||||||||
| 82 | 2 | $self->build_requires( $meta->{build_requires} ); | |||||||||
| 83 | } | ||||||||||
| 84 | else { | ||||||||||
| 85 | 0 | $self->error( "No META.yml found in ". $self->dist_dir ); | |||||||||
| 86 | } | ||||||||||
| 87 | 2 | return $self; | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | |||||||||||
| 91 | 1 | 1; | |||||||||
| 92 | __END__ | ||||||||||