File: Depends.pm

package info (click to toggle)
libmodule-depends-perl 0.07-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 88 kB
  • ctags: 15
  • sloc: perl: 146; makefile: 50
file content (124 lines) | stat: -rw-r--r-- 2,552 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
use strict;
package Module::Depends;
use YAML qw( LoadFile );
use Cwd qw( getcwd );
use base qw( Class::Accessor::Chained );
use File::chdir;
__PACKAGE__->mk_accessors(qw( dist_dir debug libs requires build_requires error ));
our $VERSION = '0.07';

=head1 NAME

Module::Depends - identify the dependencies of a distribution

=head1 SYNOPSIS

 use YAML;
 use Module::Depends;
 my $deps = Module::Depends->new->dist_dir( '.' )->find_modules;
 print "Our dependencies:\n", Dump $deps->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->SUPER::new({
        libs           => [],
        requires       => {},
        build_requires => {},
        error          => '',
    });
}

=head2 dist_dir

Path where the distribution has been extracted to.

=head2 find_modules

scan the C<dist_dir> to populate C<libs>, C<requires>, and C<build_requires>

=cut

sub find_modules {
    my $self = shift;

    my $going_to = File::Spec->rel2abs( $self->dist_dir );
    local $CWD = $going_to;
    $CWD eq $going_to
     ? $self->_find_modules
     : $self->error( "couldn't chdir to " . $self->dist_dir . ": $!" );
    return $self;
}

sub _find_modules {
    my $self = shift;

    my $file = 'META.yml';
    if (-e $file) {
        my $meta = LoadFile( $file );
        $self->requires( $meta->{requires} );
        $self->build_requires( $meta->{build_requires} );
    }
    else {
        $self->error( "No META.yml found in ". $self->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 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 2004 Fotango.  All Rights Reserved.

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

=head1 SEE ALSO

L<Module::Depends::Intrusive>

=cut