| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Ado::Plugin::Routes; | 
| 2 | 23 |  |  | 23 |  | 26519 | use Mojo::Base 'Ado::Plugin'; | 
|  | 23 |  |  |  |  | 44 |  | 
|  | 23 |  |  |  |  | 182 |  | 
| 3 |  |  |  |  |  |  |  | 
| 4 |  |  |  |  |  |  | sub register { | 
| 5 | 23 |  |  | 23 | 1 | 1497 | my ($self, $app, $conf) = shift->initialise(@_); | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | #Add some conditions: Someday | 
| 8 |  |  |  |  |  |  | #    $app->routes->add_condition( | 
| 9 |  |  |  |  |  |  | #        require_formats => sub { | 
| 10 |  |  |  |  |  |  | #            my ($route, $c, $captures, $formats) = @_; | 
| 11 |  |  |  |  |  |  | #            $c->debug('$route, $c, $captures, $formats:' | 
| 12 |  |  |  |  |  |  | #                  . $c->dumper( $route, ref $c, $captures, $formats)); | 
| 13 |  |  |  |  |  |  | #             #Carp::cluck(caller); | 
| 14 |  |  |  |  |  |  | #            return ($c->require_formats($formats) ? 1 : undef); | 
| 15 |  |  |  |  |  |  | #        } | 
| 16 |  |  |  |  |  |  | #    ); | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | # Rewrite urls in case we are deployed under Apache and using mod_cgi or mod_fcgid. | 
| 19 |  |  |  |  |  |  | # This way we have the same urls as if deployed standalone or with hypnotoad. | 
| 20 |  |  |  |  |  |  | # See templates/partials/apache2htaccess.ep | 
| 21 |  |  |  |  |  |  | $app->hook( | 
| 22 |  |  |  |  |  |  | before_dispatch => sub { | 
| 23 | 0 |  | 0 | 0 |  | 0 | state $cgi = $_[0]->req->env->{GATEWAY_INTERFACE} // '' =~ m/^CGI/; | 
| 24 | 0 | 0 |  |  |  | 0 | $_[0]->req->url->base->path($conf->{base_url_path}) if $cgi; | 
| 25 |  |  |  |  |  |  | } | 
| 26 | 23 | 50 |  |  |  | 101 | ) if $conf->{base_url_path}; | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 23 |  |  |  |  | 627 | return $self; | 
| 29 |  |  |  |  |  |  | } | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | 1; | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | =pod | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | =encoding utf8 | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | =head1 NAME | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | Ado::Plugin::Routes - Keep routes separately. | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | #Open $MOJO_HOME/etc/plugins/routes.conf and describe your routes | 
| 47 |  |  |  |  |  |  | routes     => [ | 
| 48 |  |  |  |  |  |  | {route => '/ado-users', via => ['GET'], | 
| 49 |  |  |  |  |  |  | to => 'ado-users#list',}, | 
| 50 |  |  |  |  |  |  | {route => '/ado-users', via => ['POST'], | 
| 51 |  |  |  |  |  |  | to => 'ado-users#add',}, | 
| 52 |  |  |  |  |  |  | ... | 
| 53 |  |  |  |  |  |  | ], | 
| 54 |  |  |  |  |  |  | base_url_path =>'/' | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | Ado::Plugin::Routes allows you to define your routes in a separate file | 
| 59 |  |  |  |  |  |  | C<$MOJO_HOME/etc/plugins/routes.conf>. In the configuration file you can also | 
| 60 |  |  |  |  |  |  | use the B> keyword and add complex routes as you would do directly in | 
| 61 |  |  |  |  |  |  | the code. | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | =head1 OPTIONS | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | =head2 base_url_path | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | Base URL which will be used to construct URLs when deployed as FCGI or CGI. | 
| 68 |  |  |  |  |  |  | Default: C. | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | =head2 routes | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | And ARRAY reference describing the routes. | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | =head1 METHODS | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | L inherits all methods from | 
| 78 |  |  |  |  |  |  | L and implements the following new ones. | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | =head2 register | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | This method is called by C<$app-Eplugin>. Registers the plugin in L | 
| 84 |  |  |  |  |  |  | application and merges routes  configuration from C<$MOJO_HOME/etc/ado.conf> | 
| 85 |  |  |  |  |  |  | with routes defined in C<$MOJO_HOME/etc/plugins/routes.conf>. Routes defined | 
| 86 |  |  |  |  |  |  | in C can overwrite those defined in C. | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | =head1 HOOKS | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | This plugin implements the following hooks. | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | =head2 before_dispatch | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | This hook is generated if you add the option L to plugin | 
| 95 |  |  |  |  |  |  | configuration. In case the application is deployed as CGI or FCGI application, | 
| 96 |  |  |  |  |  |  | the url part containing C is removed from the base url path so the  urls | 
| 97 |  |  |  |  |  |  | are the same as if deployed standalone or with | 
| 98 |  |  |  |  |  |  | L. The configuration for Apache is expected | 
| 99 |  |  |  |  |  |  | to be generated by L. | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | =cut | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | # =head1 CONDITIONS | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | # This plugin provides some convenient conditions that you can add to | 
| 106 |  |  |  |  |  |  | # your routes. They will be always available and you can use them | 
| 107 |  |  |  |  |  |  | # in your plugins. How to write I is explained in | 
| 108 |  |  |  |  |  |  | # L and L. | 
| 109 |  |  |  |  |  |  | # TODO. | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | #=head2 require_formats | 
| 112 |  |  |  |  |  |  | # | 
| 113 |  |  |  |  |  |  | #Adds a more user friendly status message "415 - Unsupported Media Type" | 
| 114 |  |  |  |  |  |  | #when you want to tell the user how to access a resourse. | 
| 115 |  |  |  |  |  |  | #See L for details. | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | L, L, | 
| 121 |  |  |  |  |  |  | L, L, L, L,L, | 
| 122 |  |  |  |  |  |  | L, | 
| 123 |  |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | =head1 SPONSORS | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | The original author | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | =head1 AUTHOR | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | Красимир Беров (Krasimir Berov) | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | Copyright 2013-2014 Красимир Беров (Krasimir Berov). | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | This program is free software, you can redistribute it and/or modify it under | 
| 138 |  |  |  |  |  |  | the terms of the  GNU Lesser General Public License v3 (LGPL-3.0). You may | 
| 139 |  |  |  |  |  |  | copy, distribute and modify the software provided that  modifications are open | 
| 140 |  |  |  |  |  |  | source. However, software that includes  the license may release under a | 
| 141 |  |  |  |  |  |  | different license. | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | See http://opensource.org/licenses/lgpl-3.0.html for more information. | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | =cut | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  |  |