NAME
Class::Forward - Traverse Class Namspaces
VERSION
version 0.100000
SYNOPSIS
package MyApp;
use Class::Forward;
sub class {
my ($self, $shorthand, @arguments) = @_;
my $class = Class::Forward->new(namespace => ref $self);
return $class->forward($shorthand, @arguments);
}
package main;
my $app = MyApp->new;
my $data = $app->class('data.new'); # returns a new MyApp::Data object
DESCRIPTION
Class::Forward is designed to simply return class names and/or dispatch
method calls using shorthand. It uses file-system path specification
conventions to match against class namespaces.
EXPORTS
clsf
The exported function clsf is responsible for resolving your shorthand.
It provides the follow functionality:
package App::Store;
use CGI;
use Class::Forward;
clsf; # returns App::Store
clsf './user'; # returns App::Store::User
clsf './user.new', name => 'N30'; # return a new App::Store::User object
clsf './user_profile.new'; # ... App::Store::UserProfile object
clsf '../user'; # returns App::User
clsf '//'; # returns App; (top of the calling class)
clsf '//.new'; # returns a new App object
clsf '//view'; # ... returns App::View
clsf '//view.new'; # ... returns a new App::View object
clsf '//view.new.render'; # ... dispatches methods in succession
clsf 'cgi'; # returns App::Store::Cgi
clsf '/cgi'; # returns Cgi (or CGI if already loaded)
# ... it tries to do the right thing
1;
The clsf function takes two arguments, the shorthand to be translated,
and an optional list of arguments to be passed to the last method
appended to the shorthand.
clsr
The exported function clsr is responsible for resolving your shorthand.
It provides the follow functionality:
package App::Store;
use CGI;
use Class::Forward;
clsr; # returns /app/store
clsr './user'; # returns /app/store/user
clsr './user.new', name => 'N30'; # returns /app/store/user
clsr './user_profile'; # returns /app/store/user_profile
clsr '../user'; # returns /app/user
clsr '//'; # returns /app
clsr '//.new'; # returns /app
clsr '//view'; # returns /app/view
clsr '//view.new'; # returns /app/view
clsr '//view.new.render'; # returns /app/view
clsr 'cgi'; # returns /app/store/cgi
clsr '/cgi'; # returns /cgi
1;
The clsr function takes two arguments, the shorthand to be translated,
and an optional list of arguments to be passed to the last method
appended to the shorthand.
SEE ALSO
Along my travels I recall visiting a similar module on the CPAN called
Namespace::Dispatch which provides somewhat of the same functionality.
AUTHOR
Al Newkirk <anewkirk@ana.io>
COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Al Newkirk.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.