[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cgiapp] ANNOUNCE: CGI::Application::Plugin::Forward 1.00


CGI::Application::Plugin::Forward is a module that allows you to pass
control from one run mode to another.

For example:

    use base 'CGI::Application';
    use CGI::Application::Plugin::Forward;

    sub setup {
        my $self = shift;
        $self->run_modes([qw(
            start
            second_runmode
        )]);
    }
    sub start {
        my $self = shift;
        return $self->forward('second_runmode');
    }
    sub second_runmode {
        my $self = shift;

        my $rm = $self->get_current_runmode;  # 'second_runmode'

    }



Calling $self->forward($other_runmode) is similar to calling
$self->$other_runmode.  The main difference is that 'forward' updates
C::A's internal "current runmode" value.  So when you call
$self->get_current_runmode from within in the new run mode, it returns
the name of the new run mode.

This is feature is useful for modules that use the name of the current
run mode.  For instance, AnyTemplate uses it to guess the name of the
template.

The other difference is that forward uses the *name* of the run mode,
not the name of the method that handles it:

    sub setup {
        my $self = shift;
        $self->run_modes({
            start         => 'start',
            other_action  => 'other_method',
        });
    }
    sub start {
        my $self = shift;
        return $self->forward('other_action');
    }
    sub other_method {
        my $self = shift;

        my $rm = $self->get_current_runmode;  # 'other_action'
    }

Finally, you can use forward to pass control to 'anonymous run modes'
(i.e. runmodes defined as coderefs):

    sub setup {
        my $self = shift;
        $self->run_modes({
            start         => 'start',
            anon_action   => sub {
                my $self = shift;
                my $rm = $self->get_current_runmode;  # 'anon_action'
            },
        });
    }
    sub start {
        my $self = shift;
        return $self->forward('anon_action');
    }


CGI::Application::Plugin::Forward is up on CPAN:

    http://search.cpan.org/dist/CGI-Application-Plugin-Forward/



Michael



--
Michael Graham <suppressed>



---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/suppressed/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.