Anton Belousov > Eidolon-Driver-Router-Consequent-0.01 > Eidolon::Driver::Router::Consequent

Download:
Eidolon-Driver-Router-Consequent-0.01.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.01   Source  

NAME ^

Eidolon::Driver::Router::Consequent - consequent request router for Eidolon.

SYNOPSIS ^

Somewhere in application controllers:

    my $r = Eidolon::Core::Registry->get_instance;
    my $router = $r->loader->get_object("Eidolon::Driver::Router::Consequent");

    print "Controller: " . $router->{"controller"}              . "\n";
    print "Handler: "    . $router->{"handler"}                 . "\n";
    print "Parameters: " . join(", ", @{ $router->{"params"} }) . "\n";

DESCRIPTION ^

The Eidolon::Driver::Router::Consequent driver finds handler for each user request. Routing is based on application "Routing table" in application configuration.

Routing flow

Each row of routing table is sequentally checked if it matches a GET-request string. The router keeps checking rows one by one till the matching one is found, otherwise "DriverError::Router::NotFound" in Eidolon::Driver::Router::Exceptions exception is thrown. If a regular expression in the routing table contains elements enclosed in round braces (), these elements assumed to be handler parameters.

After handler was found, router checks its security policy. If application was defined as a private in configuration (see Eidolon::Core::Config for more information) and a routing rule isn't marked as public - "DriverError::Router::Forbidden" in Eidolon::Driver::Router::Exceptions exception is thrown. Also, this exception is thrown if a handler has got a private mark, without application configuration dependencies.

Routing table

The routing table must be defined in application configuration (Eidolon::Core::Config) hash using {"routes"} key. For example, this could be in your application's lib/Example/Config.pm file:

    package Example;

    use base Eidolon::Core::Config;
    use warnings;
    use strict;

    our $VERSION  = "0.01";

    sub new
    {
        my ($class, $name, $type, $self);

        ($class, $name, $type) = @_;

        $self = $class->SUPER::new($name, $type);

        # ...

        # application routing table
        $self->{"routes"} =
        {
            "/"          => [ "Example::Controller::Default"                      ],
            "news"       => [ "Example::Controller::News"                         ],
            "news/(\d+)" => [ "Example::Controller::News",   "entry"              ],
            "admin"      => [ "Example::Controller::Admin",  "default", "private" ]
        };

        return $self;
    }

As you can see from example below, the routing table is a hash reference, and each key-value pair of it represents a single routing rule.

METHODS ^

new()

Inherited from "new()" in Eidolon::Driver::Router.

find_handler()

Implementation of abstract method from "find_handler()" in Eidolon::Driver::Router.

get_handler()

Inherited from "get_handler()" in Eidolon::Driver::Router.

get_params()

Inherited from "get_params()" in Eidolon::Driver::Router.

SEE ALSO ^

Eidolon, Eidolon::Applicaton, Eidolon::Driver::Router

LICENSE ^

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

AUTHOR ^

Anton Belousov, <abel@cpan.org>

COPYRIGHT ^

Copyright (c) 2009, Atma 7, http://www.atma7.com

syntax highlighting: