Skip to content

Commit

Permalink
move introspection recipe to basics
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Nov 2, 2011
1 parent 699f21e commit 3597a41
Showing 1 changed file with 45 additions and 45 deletions.
90 changes: 45 additions & 45 deletions lib/Mojolicious/Guides/Routing.pod
Expand Up @@ -569,10 +569,55 @@ You can also add your own shortcuts to make route generation more expressive.
Shortcuts can lead to anything, routes, bridges or maybe even both.
And watch out for quicksand!

=head2 Introspection

The C<routes> command can be used from the command line to list all available
routes together with name and underlying regular expressions.

$ script/myapp routes -v
/foo/:name GET fooname ^/foo/([^/\.]+))(?:\.([^/]+)$)?
/baz/*everything POST bazeverything ^/baz/(.+))(?:\.([^/]+)$)?
/bar/(.test) * bartest ^/bar/([^/]+))(?:\.([^/]+)$)?

=head1 ADVANCED

Less commonly used and more powerful features.

=head2 IRIs

IRIs are handled transparently, that means paths are guaranteed to be
unescaped and decoded to Perl characters.

use utf8;

# /☃ (unicode snowman) -> {controller => 'foo', action => 'snowman'}
$r->route('/☃')->to(controller => 'foo', action => 'snowman');

Just don't forget to use the L<utf8> pragma or you'll make the unicode
snowman very sad.

=head2 WebSockets

You can restrict access to WebSocket handshakes using the C<websocket> method.

# /echo (WebSocket handshake)
$r->websocket('/echo')->to(controller => 'foo', action => 'echo');

# Controller
package MyApp::Foo;
use Mojo::Base 'Mojolicious::Controller';

# Action
sub echo {
my $self = shift;
$self->on(message => sub {
my ($self, $message) = @_;
$self->send_message("echo: $message");
});
}

1;

=head2 Conditions

Sometimes you might need a little more power, for example to check the
Expand Down Expand Up @@ -752,51 +797,6 @@ Now just load the plugin and you're done.

1;

=head2 WebSockets

You can restrict access to WebSocket handshakes using the C<websocket> method.

# /echo (WebSocket handshake)
$r->websocket('/echo')->to(controller => 'foo', action => 'echo');

# Controller
package MyApp::Foo;
use Mojo::Base 'Mojolicious::Controller';

# Action
sub echo {
my $self = shift;
$self->on(message => sub {
my ($self, $message) = @_;
$self->send_message("echo: $message");
});
}

1;

=head2 IRIs

IRIs are handled transparently, that means paths are guaranteed to be
unescaped and decoded to Perl characters.

use utf8;

# /☃ (unicode snowman) -> {controller => 'foo', action => 'snowman'}
$r->route('/☃')->to(controller => 'foo', action => 'snowman');

Just don't forget to use the L<utf8> pragma or you'll make the unicode
snowman very sad.

=head2 Introspection

The C<routes> command can be used from the command line to list all available
routes together with name and underlying regular expressions.

$ script/myapp routes -v
/foo/:name GET fooname ^/foo/([^/\.]+))(?:\.([^/]+)$)?
/baz/*everything POST bazeverything ^/baz/(.+))(?:\.([^/]+)$)?
/bar/(.test) * bartest ^/bar/([^/]+))(?:\.([^/]+)$)?

=head1 MORE

You can continue with L<Mojolicious::Guides> now or take a look at the
Expand Down

0 comments on commit 3597a41

Please sign in to comment.