Debian lenny version packages
[pkg-perl] / deb-src / libmodule-depends-perl / libmodule-depends-perl-0.14 / lib / Module / Depends.pm
1 use strict;
2 package Module::Depends;
3 use YAML qw( LoadFile );
4 use Cwd qw( getcwd );
5 use base qw( Class::Accessor::Chained );
6 __PACKAGE__->mk_accessors(qw( dist_dir debug libs requires build_requires error ));
7 our $VERSION = '0.14';
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 sub new {
39     my $self = shift;
40
41     return $self->SUPER::new({
42         libs           => [],
43         requires       => {},
44         build_requires => {},
45         error          => '',
46     });
47 }
48
49 =head2 dist_dir
50
51 Path where the distribution has been extracted to.
52
53 =head2 find_modules
54
55 scan the C<dist_dir> to populate C<libs>, C<requires>, and C<build_requires>
56
57 =cut
58
59 sub find_modules {
60     my $self = shift;
61
62     my $here = getcwd;
63     unless (chdir $self->dist_dir) {
64         $self->error( "couldn't chdir to " . $self->dist_dir . ": $!" );
65         return $self; 
66     }
67     eval { $self->_find_modules };
68     chdir $here;
69     die $@ if $@;
70     
71     return $self;
72 }
73
74 sub _find_modules {
75     my $self = shift;
76
77     my $file = 'META.yml';
78     if (-e $file) {
79         my $meta = LoadFile( $file );
80         $self->requires( $meta->{requires} );
81         $self->build_requires( $meta->{build_requires} );
82     }
83     else {
84         $self->error( "No META.yml found in ". $self->dist_dir );
85     }
86     return $self;
87 }
88
89
90 1;
91 __END__
92
93 =head2 libs
94
95 an array reference of lib lines
96
97 =head2 requires
98
99 A reference to a hash enumerating the prerequisite modules for this
100 distribution.
101
102 =head2 build_requires
103
104 A reference to a hash enumerating the modules needed to build the
105 distribution.
106
107 =head2 error
108
109 A reason, if any, for failing to get dependencies.
110
111 =head1 AUTHOR
112
113 Richard Clamp, based on code extracted from the Fotango build system
114 originally by James Duncan and Arthur Bergman.
115
116 =head1 COPYRIGHT
117
118 Copyright 2004, 2007, 2008 Fotango.  All Rights Reserved.
119
120 This module is free software; you can redistribute it and/or modify it
121 under the same terms as Perl itself.
122
123 =head1 SEE ALSO
124
125 L<Module::Depends::Intrusive>
126
127 =cut