Module::Install::Base - Base class for Module::Install extensions


Module-Install documentation Contained in the Module-Install distribution.

Index


Code Index:

NAME

Top

Module::Install::Base - Base class for Module::Install extensions

SYNOPSIS

Top

In a Module::Install extension:

    use Module::Install::Base ();
    @ISA = qw(Module::Install::Base);

DESCRIPTION

Top

This module provide essential methods for all Module::Install extensions, in particular the common constructor new and method dispatcher AUTOLOAD.

METHODS

Top

new(%args)

Constructor -- need to preserve at least _top

AUTOLOAD

The main dispatcher - copy extensions if missing

_top()

Returns the top-level Module::Install object.

admin()

Returns the _top object's associated Module::Install::Admin object on the first run (i.e. when there was no inc/ when the program started); on subsequent (user-side) runs, returns a fake admin object with an empty AUTOLOAD method that does nothing at all.

is_admin()

Tells whether this is the first run of the installer (on author's side). That is when there was no inc/ at program start. True if that's the case. False, otherwise.

SEE ALSO

Top

Module::Install

AUTHORS

Top

Audrey Tang <autrijus@autrijus.org>

COPYRIGHT

Top


Module-Install documentation Contained in the Module-Install distribution.
package Module::Install::Base;

use strict 'vars';
use vars qw{$VERSION};
BEGIN {
	$VERSION = '1.01';
}

# Suspend handler for "redefined" warnings
BEGIN {
	my $w = $SIG{__WARN__};
	$SIG{__WARN__} = sub { $w };
}

sub new {
	my $class = shift;
	unless ( defined &{"${class}::call"} ) {
		*{"${class}::call"} = sub { shift->_top->call(@_) };
	}
	unless ( defined &{"${class}::load"} ) {
		*{"${class}::load"} = sub { shift->_top->load(@_) };
	}
	bless { @_ }, $class;
}

sub AUTOLOAD {
	local $@;
	my $func = eval { shift->_top->autoload } or return;
	goto &$func;
}

sub _top {
	$_[0]->{_top};
}

sub admin {
	$_[0]->_top->{admin}
	or
	Module::Install::Base::FakeAdmin->new;
}

sub is_admin {
	! $_[0]->admin->isa('Module::Install::Base::FakeAdmin');
}

sub DESTROY {}

package Module::Install::Base::FakeAdmin;

use vars qw{$VERSION};
BEGIN {
	$VERSION = $Module::Install::Base::VERSION;
}

my $fake;

sub new {
	$fake ||= bless(\@_, $_[0]);
}

sub AUTOLOAD {}

sub DESTROY {}

# Restore warning handler
BEGIN {
	$SIG{__WARN__} = $SIG{__WARN__}->();
}

1;