| 1 | package Acme::Everything; | ||
| 2 | |||
| 3 | # A _huge_ amount of work went into making sure Class::Autouse handles | ||
| 4 | # pretty much every corner case properly, so we'll just hook into it, | ||
| 5 | # rather than writing our own autoload code. | ||
| 6 | use 5.006; | ||
| 7 | use strict; | ||
| 8 | use Class::Autouse ':superloader'; | ||
| 9 | |||
| 10 | our $VERSION = '1.01'; | ||
| 11 | |||
| 12 | # Define our replacement load method | ||
| 13 | sub _load { | ||
| 14 | # We'll try to do this the normal way once, | ||
| 15 | # and if that doesn't work, we'll bring CPANPLUS into it. | ||
| 16 | eval { $_ = Class::Autouse::__load( @_ ) }; | ||
| 17 | |||
| 18 | # We only care if we couldn't find the class | ||
| 19 | return $_ unless $@; | ||
| 20 | die $@ unless $@ =~ /^Can't locate /; | ||
| 21 | |||
| 22 | # Try to install the module, and then call __load again. | ||
| 23 | # But this time, don't catch errors. | ||
| 24 | require CPANPLUS; | ||
| 25 | CPANPLUS::install( $_[0] ); | ||
| 26 | Class::Autouse::__load( @_ ); | ||
| 27 | } | ||
| 28 | |||
| 29 | # Replace Class::Autouse's version with ours | ||
| 30 | *Class::Autouse::__load = *Class::Autouse::_load; | ||
| 31 | *Class::Autouse::_load = *_load; | ||
| 32 | |||
| 33 | 1; | ||
| 34 | |||
| 35 | __END__ |