<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">use strict;
package Module::Depends;
use CPAN::Meta;
use Cwd qw( getcwd );
use base qw( Class::Accessor::Chained );
__PACKAGE__-&gt;mk_accessors(qw( dist_dir debug libs requires configure_requires build_requires test_requires error ));
our $VERSION = '0.16';

=head1 NAME

Module::Depends - identify the dependencies of a distribution

=head1 SYNOPSIS

 use Module::Depends;
 my $deps = Module::Depends-&gt;new-&gt;dist_dir( '.' )-&gt;find_modules;
 print "Our dependencies:\n", Dump $deps-&gt;requires;

=head1 DESCRIPTION

Module::Depends extracts module dependencies from an unpacked
distribution tree.

Module::Depends only evaluates the META.yml shipped with a
distribution.  This won't be effective until all distributions ship
META.yml files, so we suggest you take your life in your hands and
look at Module::Depends::Intrusive.

=head1 METHODS

=head2 new

simple constructor

=cut

sub new {
    my $self = shift;

    return $self-&gt;SUPER::new({
        libs           =&gt; [],
        requires       =&gt; {},
        build_requires =&gt; {},
        test_requires  =&gt; {},
        configure_requires =&gt; {},
        error          =&gt; '',
    });
}

=head2 dist_dir

Path where the distribution has been extracted to.

=head2 find_modules

scan the C&lt;dist_dir&gt; to populate C&lt;libs&gt;, C&lt;requires&gt;, C&lt;configure_requires&gt;, C&lt;test_requires&gt;, and C&lt;build_requires&gt;

=cut

sub find_modules {
    my $self = shift;

    my $here = getcwd;
    unless (chdir $self-&gt;dist_dir) {
        $self-&gt;error( "couldn't chdir to " . $self-&gt;dist_dir . ": $!" );
        return $self; 
    }
    eval { $self-&gt;_find_modules };
    chdir $here;
    die $@ if $@;
    
    return $self;
}

sub _find_modules {
    my $self = shift;

    my ($file) = grep { -e $_ } qw( MYMETA.json MYMETA.yml META.json META.yml );
    if ($file) {
        my $meta = CPAN::Meta-&gt;load_file( $file );
        my $prereqs = $meta-&gt;effective_prereqs();
        $self-&gt;requires( $prereqs-&gt;requirements_for( 'runtime', 'requires' )-&gt;as_string_hash() );
        $self-&gt;build_requires( $prereqs-&gt;requirements_for( 'build', 'requires' )-&gt;as_string_hash() );
        $self-&gt;configure_requires( $prereqs-&gt;requirements_for( 'configure', 'requires' )-&gt;as_string_hash() );
        $self-&gt;test_requires( $prereqs-&gt;requirements_for( 'test', 'requires' )-&gt;as_string_hash() );
    }
    else {
        $self-&gt;error( "No {MY,}META.{json,yml} found in ". $self-&gt;dist_dir );
    }
    return $self;
}


1;
__END__

=head2 libs

an array reference of lib lines

=head2 requires

A reference to a hash enumerating the prerequisite modules for this
distribution.

=head2 configure_requires

A reference to a hash enumerating the prerequisite modules to configure this
distribution.

=head2 build_requires

A reference to a hash enumerating the modules needed to build the
distribution.

=head2 error

A reason, if any, for failing to get dependencies.

=head1 AUTHOR

Richard Clamp, based on code extracted from the Fotango build system
originally by James Duncan and Arthur Bergman.

=head1 COPYRIGHT

Copyright 2010, Richard Clamp.
Copyright 2004-2008, Fotango.

This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=head1 SEE ALSO

L&lt;Module::Depends::Intrusive&gt;

=cut
</pre></body></html>