1 #line 1 "inc/Module/Install.pm - /Library/Perl/5.8.1/Module/Install.pm"
2 # $File: //depot/cpan/Module-Install/lib/Module/Install.pm $ $Author: autrijus $
3 # $Revision: #67 $ $Change: 1885 $ $DateTime: 2004/03/11 05:55:27 $ vim: expandtab shiftwidth=4
5 package Module::Install;
8 die << "." unless $INC{join('/', inc => split(/::/, __PACKAGE__)).'.pm'};
9 Please invoke ${\__PACKAGE__} with:
11 use inc::${\__PACKAGE__};
24 @inc::Module::Install::ISA = 'Module::Install';
30 my $self = $class->new(@_);
32 if (not -f $self->{file}) {
33 require "$self->{path}/$self->{dispatch}.pm";
34 File::Path::mkpath("$self->{prefix}/$self->{author}");
36 "$self->{name}::$self->{dispatch}"->new(_top => $self);
38 @_ = ($class, _self => $self);
39 goto &{"$self->{name}::import"};
42 *{caller(0) . "::AUTOLOAD"} = $self->autoload;
44 # Unregister loader and worker packages so subdirs can use them again
45 delete $INC{"$self->{file}"};
46 delete $INC{"$self->{path}.pm"};
56 my $sym = "$caller\::AUTOLOAD";
60 if (my $code = $sym->{$pwd}) {
61 goto &$code unless $cwd eq $pwd; # delegate back to parent dirs
63 $$sym =~ /([^:]+)$/ or die "Cannot autoload $caller";
64 unshift @_, ($self, $1);
65 goto &{$self->can('call')} unless uc($1) eq $1;
72 my ($class, %args) = @_;
74 return $args{_self} if $args{_self};
76 $args{dispatch} ||= 'Admin';
77 $args{prefix} ||= 'inc';
78 $args{author} ||= '.author';
79 $args{bundle} ||= 'inc/BUNDLES';
81 $class =~ s/^\Q$args{prefix}\E:://;
82 $args{name} ||= $class;
83 $args{version} ||= $class->VERSION;
85 unless ($args{path}) {
86 $args{path} = $args{name};
87 $args{path} =~ s!::!/!g;
89 $args{file} ||= "$args{prefix}/$args{path}.pm";
91 bless(\%args, $class);
99 my $obj = $self->load($method) or return;
102 goto &{$obj->can($method)};
108 my ($self, $method) = @_;
110 $self->load_extensions(
111 "$self->{prefix}/$self->{path}", $self
112 ) unless $self->{extensions};
114 foreach my $obj (@{$self->{extensions}}) {
115 return $obj if $obj->can($method);
118 my $admin = $self->{admin} or die << "END";
119 The '$method' method does not exist in the '$self->{prefix}' path!
120 Please remove the '$self->{prefix}' directory and run $0 again to load it.
123 my $obj = $admin->load($method, 1);
124 push @{$self->{extensions}}, $obj;
131 sub load_extensions {
132 my ($self, $path, $top_obj) = @_;
134 unshift @INC, $self->{prefix}
135 unless grep { $_ eq $self->{prefix} } @INC;
137 local @INC = ($path, @INC);
138 foreach my $rv ($self->find_extensions($path)) {
139 my ($file, $pkg) = @{$rv};
140 next if $self->{pathnames}{$pkg};
142 eval { require $file; 1 } or (warn($@), next);
143 $self->{pathnames}{$pkg} = delete $INC{$file};
144 push @{$self->{extensions}}, $pkg->new( _top => $top_obj );
150 sub find_extensions {
151 my ($self, $path) = @_;
154 File::Find::find(sub {
155 my $file = $File::Find::name;
156 return unless $file =~ m!^\Q$path\E/(.+)\.pm\Z!is;
157 return if $1 eq $self->{dispatch};
159 $file = "$self->{path}/$1.pm";
160 my $pkg = "$self->{name}::$1"; $pkg =~ s!/!::!g;
161 push @found, [$file, $pkg];
162 }, $path) if -d $path;