aliased::factory - shorter versions of a class tree's constructors
use aliased::factory YAPI => 'Yahoo::Marketing';
my $service = YAPI->KeywordResearchService->new(...);
my $res = $service->getRelatedKeywords(
This package is similar to aliased, but performs on-demand loading for packages below the shortened 'root package'. For example, the above code will automatically load the KeywordResearchService and RelatedKeywordRequestType packages from the Yahoo::Marketing:: hierarchy.
To load a second-level package:
use aliased::factory BAR => 'Foo::Bar';
my $bort = BAR->Baz->Bort->new(...);
This would load the Foo::Bar::Baz and then Foo::Bar::Baz::Bort packages. Each method call require()s the corresponding package and returns an aliased::factory object, which has a new() method (see below.)
Returns a new object of the class represented by the $factory object.
my $instantiated = $factory->new(...);
The class being instantiated must have a new() method.
The rest of this is functionality used to create the factory.
Installs a sub 'shortname' in your package containing an object pointed at $package.
aliased::factory->import(shortname => $package);
When called on a factory object, attempts to require the subpackage. If this succeeds, it will return a coderef (which will return the subfactory when executed.)
my $coderef = $factory->can('subpackage');
This method is used by AUTOLOAD().
Attempts to load the $factory's corresponding subpackage, returns a the subfactory object or throws a fatal error: "Can't locate ... in @INC ...".
my $subfactory = $factory->subpackage;
Eric Wilhelm @ <ewilhelm at cpan dot org>
If you found this module on CPAN, please report any bugs or feature requests through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
If you pulled this development version from my /svn/, please contact me directly.
Copyright (C) 2009 Eric L. Wilhelm, All Rights Reserved.
Thanks to HDP for the suggestion of using a factory object.
Absolutely, positively NO WARRANTY, neither express or implied, is offered with this software. You use this software at your own risk. In case of loss, no person or entity owes you anything whatsoever. You have been warned.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install aliased::factory, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.