Skip to content

Commit

Permalink
added r function to ojo (closes #339)
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jun 19, 2012
1 parent 72c23a2 commit abf911b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,12 +1,13 @@

3.0 2012-06-18
3.0 2012-06-19
- Code name "Rainbow", this is a major release.
- Removed Mojolicious::Plugin::I18N so it can be maintained as a separate
distribution.
- Renamed Mojo::CookieJar to Mojo::UserAgent::CookieJar.
- Updated IO::Socket::SSL requirement to 1.75 for IO::Socket::IP support.
- Switched back from IO::Socket::INET6 to IO::Socket::IP for IPv6 support.
- Switched from HMAC-MD5 to HMAC-SHA1 for signed cookies.
- Added r function to ojo. (sharifulin, sri)
- Added support for new HTTP status code.
- Improved message parser performance slightly.
- Improved documentation. (ichesnokov, sri)
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious/Controller.pm
Expand Up @@ -890,8 +890,8 @@ timeout, which usually defaults to C<15> seconds.
$c = $c->session(foo => 'bar');
Persistent data storage, all session data gets serialized with L<Mojo::JSON>
and stored in C<HMAC-SHA1> signed cookies, which usually have a 4096 byte
limit, depending on browser.
and stored in C<HMAC-SHA1> signed cookies. Note that cookies usually have a
4096 byte limit, depending on browser.
# Manipulate session
$c->session->{foo} = 'bar';
Expand Down
10 changes: 8 additions & 2 deletions lib/ojo.pm
Expand Up @@ -36,16 +36,16 @@ sub import {
$UA->app(*{"${caller}::app"}->());

# Functions
*{"${caller}::a"} = sub { *{"${caller}::any"}->(@_) and return $UA->app };
*{"${caller}::b"} = \&b;
*{"${caller}::c"} = \&c;
*{"${caller}::a"}
= sub { *{"${caller}::any"}->(@_) and return *{"${caller}::app"}->() };
*{"${caller}::d"} = sub { _request($UA->build_tx(DELETE => @_)) };
*{"${caller}::f"} = sub { _request($UA->build_form_tx(@_)) };
*{"${caller}::g"} = sub { _request($UA->build_tx(GET => @_)) };
*{"${caller}::h"} = sub { _request($UA->build_tx(HEAD => @_)) };
*{"${caller}::o"} = sub { _request($UA->build_tx(OPTIONS => @_)) };
*{"${caller}::p"} = sub { _request($UA->build_tx(POST => @_)) };
*{"${caller}::r"} = sub { $UA->app->dumper(@_) };
*{"${caller}::t"} = sub { _request($UA->build_tx(PATCH => @_)) };
*{"${caller}::u"} = sub { _request($UA->build_tx(PUT => @_)) };
*{"${caller}::x"} = sub { Mojo::DOM->new(@_) };
Expand Down Expand Up @@ -159,6 +159,12 @@ resulting L<Mojo::Message::Response> object.
Perform C<POST> request with L<Mojo::UserAgent/"post"> and return resulting
L<Mojo::Message::Response> object.
=head2 C<r>
my $perl = r({data => 'structure'});
Dump a Perl data structure using L<Data::Dumper>.
=head2 C<t>
my $res = t('mojolicio.us');
Expand Down
8 changes: 6 additions & 2 deletions t/mojolicious/ojo.t
Expand Up @@ -10,7 +10,7 @@ BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}

use Test::More tests => 11;
use Test::More tests => 13;

# "What do you mean 'we', flesh-tube?"
use ojo;
Expand All @@ -21,7 +21,8 @@ a(
my $self = shift;
$self->render(text => $self->req->method . ($self->param('foo') || ''));
}
);
)->secret('foobarbaz');
is a->secret, 'foobarbaz', 'right secret';

# GET /
is g('/')->body, 'GET', 'right content';
Expand Down Expand Up @@ -55,3 +56,6 @@ is b('<foo>')->url_escape, '%3Cfoo%3E', 'right result';

# Collection
is c(1, 2, 3)->join('-'), '1-2-3', 'right result';

# Dumper
is r([1, 2]), "[\n 1,\n 2\n]\n", 'right result';

0 comments on commit abf911b

Please sign in to comment.