Skip to content

Commit

Permalink
reduced memory usage of dom method in Mojo::Message
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jul 24, 2012
1 parent aab2f1f commit 7503128
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

3.13 2012-07-23
3.13 2012-07-24
- Added remove method to Mojo::DOM.
- Improved RFC 3986 compliance of Mojo::Parameters.
- Improved Mojolicious::Plugin::Config log messages. (jberger)
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Message.pm
Expand Up @@ -124,11 +124,11 @@ sub dom {
my $self = shift;

return if $self->is_multipart;
my $dom = $self->{dom} = Mojo::DOM->new;
my $dom = Mojo::DOM->new;
$dom->charset($self->content->charset);
$dom->parse($self->body);

return @_ ? $dom->find(@_) : $dom;
return @_ ? ($self->{dom} = $dom)->find(@_) : $dom;
}

# DEPRECATED in Rainbow!
Expand Down
5 changes: 4 additions & 1 deletion t/mojo/response.t
@@ -1,6 +1,6 @@
use Mojo::Base -strict;

use Test::More tests => 371;
use Test::More tests => 372;

# "Quick Smithers. Bring the mind eraser device!
# You mean the revolver, sir?
Expand Down Expand Up @@ -728,6 +728,9 @@ is_deeply [$res->dom('p > a')->pluck('text')->each], [qw(bar baz)],
my @text = $res->dom('a')->pluck(replace_content => 'yada')
->first->root->find('p > a')->pluck('text')->each;
is_deeply \@text, [qw(yada yada)], 'right values';
@text = $res->dom->find('a')->pluck(replace_content => 'test')
->first->root->find('p > a')->pluck('text')->each;
is_deeply \@text, [qw(test test)], 'right values';

# Build DOM from response with charset
$res = Mojo::Message::Response->new;
Expand Down

0 comments on commit 7503128

Please sign in to comment.