Skip to content

Commit

Permalink
better transaction examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jul 25, 2012
1 parent d7521a1 commit 9349cd5
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Changes
@@ -1,4 +1,7 @@

3.14 2012-07-25
- Improved documentation.

3.13 2012-07-24
- Added multi name support to param method in Mojolicious::Controller.
- Added remove method to Mojo::DOM.
Expand Down
18 changes: 18 additions & 0 deletions lib/Mojo/Transaction/HTTP.pm
Expand Up @@ -255,7 +255,25 @@ Mojo::Transaction::HTTP - HTTP 1.1 transaction container
use Mojo::Transaction::HTTP;
# Client
my $tx = Mojo::Transaction::HTTP->new;
$tx->req->method('GET');
$tx->req->url->parse('http://mojolicio.us');
$tx->req->headers->accept('application/json');
$tx->resume;
say $tx->res->code;
say $tx->res->headers->content_type;
say $tx->res->body;
# Server
my $tx = Mojo::Transaction::HTTP->new;
say $tx->req->method;
say $tx->req->url->to_abs;
say $tx->req->headers->accept;
$tx->res->code(200);
$tx->res->headers->content_type('text/plain');
$tx->res->body('Hello World!');
$tx->resume;
=head1 DESCRIPTION
Expand Down
6 changes: 6 additions & 0 deletions lib/Mojo/Transaction/WebSocket.pm
Expand Up @@ -306,7 +306,13 @@ Mojo::Transaction::WebSocket - WebSocket transaction container
use Mojo::Transaction::WebSocket;
# Send and receive WebSocket messages
my $ws = Mojo::Transaction::WebSocket->new;
$ws->send('Hello World!');
$ws->on(message => sub {
my ($ws, $message) = @_;
say "Message: $message";
});
=head1 DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious.pm
Expand Up @@ -34,7 +34,7 @@ has static => sub { Mojolicious::Static->new };
has types => sub { Mojolicious::Types->new };

our $CODENAME = 'Rainbow';
our $VERSION = '3.13';
our $VERSION = '3.14';

# "These old doomsday devices are dangerously unstable.
# I'll rest easier not knowing where they are."
Expand Down
5 changes: 4 additions & 1 deletion lib/Mojolicious/Types.pm
Expand Up @@ -90,12 +90,15 @@ the following ones.
=head2 C<detect>
my $ext = $types->detect('application/json;q=9');
my $exts = $types->detect('application/json;q=9');
Detect file extensions from C<Accept> header value. Unspecific values that
contain more than one MIME type are currently ignored, since browsers often
don't really know what they actually want.
# List detected extensions
say for @{$types->detect('application/json')};
=head2 C<type>
my $type = $types->type('png');
Expand Down
2 changes: 1 addition & 1 deletion t/mojo/response.t
Expand Up @@ -626,7 +626,7 @@ is_deeply $res->json, {foo => 'bar', baz => [1, 2, 3]}, 'right JSON data';
is $res->json('/foo'), 'bar', 'right result';
is $res->json('/baz/1'), 2, 'right result';
is_deeply $res->json('/baz'), [1, 2, 3], 'right result';
$res->json->{baz}->[1] = 4;
$res->json->{baz}[1] = 4;
is_deeply $res->json('/baz'), [1, 4, 3], 'right result';

# Parse response and extract HTML
Expand Down

0 comments on commit 9349cd5

Please sign in to comment.