Skip to content

Commit

Permalink
deprecated Mojo::Message->dom_class and Mojo::Message->json_class
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jul 20, 2012
1 parent 2599c37 commit 093bcb1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 41 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,9 +1,10 @@

3.12 2012-07-20
- Deprecated Mojo::Message->dom_class.
- Deprecated Mojo::Message->json_class.
- Added json method to Mojo::UserAgent::Transactor.
- Added build_json_tx and post_json methods to Mojo::UserAgent.
- Added post_json_ok method to Test::Mojo.
- Added json_class attribute to Mojo::UserAgent::Transactor.
- Added n function to ojo.
- Improved text_field helper to always set the type attribute. (marty, sri)
- Improved documentation.
Expand Down
34 changes: 14 additions & 20 deletions lib/Mojo/Message.pm
Expand Up @@ -14,8 +14,6 @@ use Scalar::Util 'weaken';

has content => sub { Mojo::Content::Single->new };
has default_charset => 'UTF-8';
has dom_class => 'Mojo::DOM';
has json_class => 'Mojo::JSON';
has max_message_size => sub { $ENV{MOJO_MAX_MESSAGE_SIZE} || 5242880 };
has version => '1.1';

Expand Down Expand Up @@ -125,12 +123,18 @@ sub cookies { croak 'Method "cookies" not implemented by subclass' }
sub dom {
my $self = shift;
return if $self->is_multipart;
my $dom = $self->dom_class->new;
my $dom = Mojo::DOM->new;
$dom->charset($self->content->charset);
$dom->parse($self->body);
return @_ ? $dom->find(@_) : $dom;
}

# DEPRECATED in Rainbow!
sub dom_class {
warn "Mojo::Message->dom_class is DEPRECATED!\n";
return @_ > 1 ? shift : 'Mojo::DOM';
}

sub error {
my $self = shift;

Expand Down Expand Up @@ -214,10 +218,16 @@ sub is_multipart { shift->content->is_multipart }
sub json {
my ($self, $pointer) = @_;
return if $self->is_multipart;
my $data = $self->json_class->new->decode($self->body);
my $data = Mojo::JSON->new->decode($self->body);
return $pointer ? Mojo::JSON::Pointer->get($data, $pointer) : $data;
}

# DEPRECATED in Rainbow!
sub json_class {
warn "Mojo::Message->json_class is DEPRECATED!\n";
return @_ > 1 ? shift : 'Mojo::JSON';
}

sub leftovers { shift->content->leftovers }

sub max_line_size { shift->headers->max_line_size(@_) }
Expand Down Expand Up @@ -513,22 +523,6 @@ Content container, defaults to a L<Mojo::Content::Single> object.
Default charset used for form data parsing, defaults to C<UTF-8>.
=head2 C<dom_class>
my $class = $message->dom_class;
$message = $message->dom_class('Mojo::DOM');
Class to be used for DOM manipulation with the C<dom> method, defaults to
L<Mojo::DOM>.
=head2 C<json_class>
my $class = $message->json_class;
$message = $message->json_class('Mojo::JSON');
Class to be used for JSON deserialization with the C<json> method, defaults to
L<Mojo::JSON>.
=head2 C<max_message_size>
my $size = $message->max_message_size;
Expand Down
16 changes: 1 addition & 15 deletions lib/Mojo/UserAgent/Transactor.pm
Expand Up @@ -13,8 +13,6 @@ use Mojo::Transaction::WebSocket;
use Mojo::URL;
use Mojo::Util qw(encode url_escape);

has json_class => 'Mojo::JSON';

sub endpoint {
my ($self, $tx) = @_;

Expand Down Expand Up @@ -98,7 +96,7 @@ sub form {

sub json {
my ($self, $url, $data) = (shift, shift, shift);
my $tx = $self->tx(POST => $url, @_, $self->json_class->new->encode($data));
my $tx = $self->tx(POST => $url, @_, Mojo::JSON->new->encode($data));
my $headers = $tx->req->headers;
$headers->content_type('application/json') unless $headers->content_type;
return $tx;
Expand Down Expand Up @@ -272,18 +270,6 @@ Mojo::UserAgent::Transactor - User agent transactor
L<Mojo::UserAgent::Transactor> is the transaction building and manipulation
framework used by L<Mojo::UserAgent>.
=head1 ATTRIBUTES
L<Mojo::UserAgent::Transactor> implements the following attributes.
=head2 C<json_class>
my $class = $t->json_class;
$t = $t->json_class('Mojo::JSON');
Class to be used for JSON serialization with the C<json> method, defaults to
L<Mojo::JSON>.
=head1 METHODS
L<Mojo::UserAgent::Transactor> inherits all methods from L<Mojo::Base> and
Expand Down
3 changes: 2 additions & 1 deletion lib/Mojolicious/Renderer.pm
Expand Up @@ -3,6 +3,7 @@ use Mojo::Base -base;

use File::Spec::Functions 'catfile';
use Mojo::Cache;
use Mojo::JSON;
use Mojo::Home;
use Mojo::Loader;
use Mojo::Util 'encode';
Expand Down Expand Up @@ -32,7 +33,7 @@ sub new {
$self->add_handler(
json => sub {
my ($r, $c, $output, $options) = @_;
$$output = $c->req->json_class->new->encode($options->{json});
$$output = Mojo::JSON->new->encode($options->{json});
}
);

Expand Down
6 changes: 3 additions & 3 deletions lib/Mojolicious/Sessions.pm
@@ -1,6 +1,7 @@
package Mojolicious::Sessions;
use Mojo::Base -base;

use Mojo::JSON;
use Mojo::Util qw(b64_decode b64_encode);

has [qw(cookie_domain secure)];
Expand All @@ -17,8 +18,7 @@ sub load {

# Deserialize
$value =~ s/-/=/g;
return
unless my $session = $c->req->json_class->new->decode(b64_decode $value);
return unless my $session = Mojo::JSON->new->decode(b64_decode $value);

# Expiration
my $expiration = $self->default_expiration;
Expand Down Expand Up @@ -56,7 +56,7 @@ sub store {
if $expiration || $default;

# Serialize
my $value = b64_encode $c->req->json_class->new->encode($session), '';
my $value = b64_encode(Mojo::JSON->new->encode($session), '');
$value =~ s/=/-/g;

# Session cookie
Expand Down
2 changes: 1 addition & 1 deletion t/pod_coverage.t
Expand Up @@ -8,4 +8,4 @@ plan skip_all => 'Test::Pod::Coverage 1.04 required for this test!'

# "Marge, I'm going to miss you so much. And it's not just the sex.
# It's also the food preparation."
all_pod_coverage_ok();
all_pod_coverage_ok({also_private => [qw(dom_class json_class)]});

0 comments on commit 093bcb1

Please sign in to comment.