Skip to content

Commit

Permalink
improved ojo exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 22, 2012
1 parent 6e73c51 commit fbbd792
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -3,6 +3,7 @@ This file documents the revision history for Perl extension Mojolicious.
2.86 2012-04-22
- Added support for TO_JSON method to Mojo::JSON.
- Improved Mojo::Template exception handling.
- Improved ojo exception handling.
- Improved documentation.

2.85 2012-04-19
Expand Down
35 changes: 11 additions & 24 deletions lib/ojo.pm
Expand Up @@ -43,36 +43,23 @@ sub import {
*{"${caller}::c"} = \&c;
*{"${caller}::a"}
= sub { *{"${caller}::any"}->(@_) and return *{"${caller}::app"}->() };
*{"${caller}::d"} = sub { _request(DELETE => @_) };
*{"${caller}::f"} = sub { _request(FORM => @_) };
*{"${caller}::g"} = sub { _request(GET => @_) };
*{"${caller}::h"} = sub { _request(HEAD => @_) };
*{"${caller}::o"} = sub { _request(OPTIONS => @_) };
*{"${caller}::p"} = sub { _request(POST => @_) };
*{"${caller}::t"} = sub { _request(PATCH => @_) };
*{"${caller}::u"} = sub { _request(PUT => @_) };
*{"${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}::t"} = sub { _request($UA->build_tx(PATCH => @_)) };
*{"${caller}::u"} = sub { _request($UA->build_tx(PUT => @_)) };
*{"${caller}::x"} = sub { Mojo::DOM->new(@_) };
}

# "I wonder what the shroud of Turin tastes like."
sub _request {

# Method
my $method = $_[0] =~ m#:|/# ? 'GET' : shift;

# Transaction
my $tx
= $method eq 'FORM'
? $UA->build_form_tx(@_)
: $UA->build_tx($method => @_);

# Process
$tx = $UA->start($tx);

# Error
my $tx = $UA->start(@_);
my ($message, $code) = $tx->error;
warn qq/Problem loading URL "$_[0]". ($message)\n/ if $message && !$code;

warn qq/Problem loading URL "@{[$tx->req->url->to_abs]}". ($message)\n/
if $message && !$code;
return $tx->res;
}

Expand Down

0 comments on commit fbbd792

Please sign in to comment.