sub
foo :Methodical {
return
[
@_
];
}
sub
_extra { () }
sub
bar {
my
$self
=
shift
;
is_deeply(
foo(1),
[
$self
->_extra,
$self
, 1 ],
"methodical as function"
,
);
is_deeply(
$self
->foo(1),
[
$self
->_extra,
$self
, 1 ],
"methodical as method"
,
);
}
BEGIN {
our
@ISA
=
qw(MyTest)
}
BEGIN {
our
@ISA
=
qw(MyTest)
}
sub
foo {
return
[
'OVERRIDE'
,
@_
];
}
sub
_extra {
'OVERRIDE'
}
BEGIN {
our
@ISA
=
'MyTest'
}
sub
bar {
my
$self
=
shift
;
is_deeply(
foo(1),
[
$self
->_extra,
$self
, 1 ],
"methodical as function (AUTOLOAD)"
,
);
eval
{ baz(); };
like $@,
qr/Undefined subroutine &MyTest::OverrideBar::baz called/
,
'AUTOLOAD does not interfere with normal missing function mechanism'
;
}
BEGIN {
our
@ISA
=
'MyTest'
}
sub
foo {
return
[
'MOREOVER'
,
@_
];
}
sub
_extra {
'MOREOVER'
}
sub
bar {
my
$self
=
shift
;
is_deeply(
foo(1),
[
$self
->_extra,
$self
, 1 ],
"methodical as function (AUTOLOAD)"
,
);
}
no
Test::More;
MyTest->bar;
MyTest::Derived->bar;
MyTest::OverrideFoo->bar;
MyTest::OverrideBar->bar;
MyTest::OverrideAll->bar;