Eric Wilhelm
and 1 contributors

NAME

aliased::factory - shorter versions of a class tree's constructors

SYNOPSIS

  use aliased::factory YAPI => 'Yahoo::Marketing';

  my $service = YAPI->KeywordResearchService->new(...);

  my $res = $service->getRelatedKeywords(
    relatedKeywordRequest =>
      YAPI->RelatedKeywordRequestType->new(...)
  );

About

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.)

Factory Method

new

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.

Meta Methods

The rest of this is functionality used to create the factory.

import

Installs a sub 'shortname' in your package containing an object pointed at $package.

  aliased::factory->import(shortname => $package);

can

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().

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;

AUTHOR

Eric Wilhelm @ <ewilhelm at cpan dot org>

http://scratchcomputing.com/

BUGS

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

Copyright (C) 2009 Eric L. Wilhelm, All Rights Reserved.

Acknowledgements

Thanks to HDP for the suggestion of using a factory object.

NO WARRANTY

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.

LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.