Base.pm 1.1 KB
Newer Older
Ruslan Zakirov's avatar
Ruslan Zakirov committed
1
2
3
#line 1
package Module::Install::Base;

Kevin Falcone's avatar
Kevin Falcone committed
4
5
6
use strict 'vars';
use vars qw{$VERSION};
BEGIN {
7
	$VERSION = '1.00';
Kevin Falcone's avatar
Kevin Falcone committed
8
}
Ruslan Zakirov's avatar
Ruslan Zakirov committed
9
10
11
12
13
14
15

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

Kevin Falcone's avatar
Kevin Falcone committed
16
#line 42
Ruslan Zakirov's avatar
Ruslan Zakirov committed
17
18

sub new {
Kevin Falcone's avatar
Kevin Falcone committed
19
20
21
22
23
24
25
26
	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;
Ruslan Zakirov's avatar
Ruslan Zakirov committed
27
28
29
30
31
}

#line 61

sub AUTOLOAD {
Kevin Falcone's avatar
Kevin Falcone committed
32
33
34
	local $@;
	my $func = eval { shift->_top->autoload } or return;
	goto &$func;
Ruslan Zakirov's avatar
Ruslan Zakirov committed
35
36
}

Kevin Falcone's avatar
Kevin Falcone committed
37
#line 75
Ruslan Zakirov's avatar
Ruslan Zakirov committed
38

Kevin Falcone's avatar
Kevin Falcone committed
39
40
41
sub _top {
	$_[0]->{_top};
}
Ruslan Zakirov's avatar
Ruslan Zakirov committed
42

Kevin Falcone's avatar
Kevin Falcone committed
43
#line 90
Ruslan Zakirov's avatar
Ruslan Zakirov committed
44
45

sub admin {
Kevin Falcone's avatar
Kevin Falcone committed
46
47
48
	$_[0]->_top->{admin}
	or
	Module::Install::Base::FakeAdmin->new;
Ruslan Zakirov's avatar
Ruslan Zakirov committed
49
50
}

Kevin Falcone's avatar
Kevin Falcone committed
51
52
#line 106

Ruslan Zakirov's avatar
Ruslan Zakirov committed
53
sub is_admin {
54
	! $_[0]->admin->isa('Module::Install::Base::FakeAdmin');
Ruslan Zakirov's avatar
Ruslan Zakirov committed
55
56
57
58
59
60
}

sub DESTROY {}

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

61
62
63
64
65
use vars qw{$VERSION};
BEGIN {
	$VERSION = $Module::Install::Base::VERSION;
}

Kevin Falcone's avatar
Kevin Falcone committed
66
67
68
69
70
my $fake;

sub new {
	$fake ||= bless(\@_, $_[0]);
}
Ruslan Zakirov's avatar
Ruslan Zakirov committed
71
72
73
74
75
76
77
78
79
80
81
82

sub AUTOLOAD {}

sub DESTROY {}

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

1;

83
#line 159