Al Newkirk > Class-Forward-0.08 > Class::Forward

Download:
Class-Forward-0.08.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 0.08   Source   Latest Release: Class-Forward-0.100006

NAME ^

Class::Forward - A class dispatcher that handles namespaces like paths

VERSION ^

version 0.08

SYNOPSIS ^

    # OO Usage and Syntax

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

    # yada yada

    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.

NOTE: Class::Forward also has support for walking up a path although this should be done with caution, writing code that executes other code based on its namespace's relativity to the current class could yield unpredictable results, especially if the calling class is ever relocated.

SEE ALSO ^

Along my travels I recall visiting a similar module on the CPAN called Namespace::Dispatch which provides somewhat of the same functionality. Additionally, since this module looks like something INGY would upload, you might want to check out his offerings also.

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.

syntax highlighting: