Skip to content

Commit

Permalink
renamed decoded_body method to text
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 20, 2013
1 parent 5fc9b8a commit 0ad8bf8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,6 +1,6 @@

4.40 2013-09-21
- Added decoded_body method to Mojo::Message.
- Added text method to Mojo::Message.
- Added siblings method to Mojo::DOM.
- Added flatten method to Mojo::Collection.
- Improved documentation browser with source links.
Expand Down
30 changes: 15 additions & 15 deletions lib/Mojo/Message.pm
Expand Up @@ -65,17 +65,10 @@ sub cookie { shift->_cache(cookies => @_) }

sub cookies { croak 'Method "cookies" not implemented by subclass' }

sub decoded_body {
my $self = shift;
my $content = $self->body;
my $charset = $self->content->charset;
return $charset ? decode($charset, $content) // $content : $content;
}

sub dom {
my $self = shift;
return undef if $self->content->is_multipart;
my $dom = $self->{dom} ||= Mojo::DOM->new($self->decoded_body);
my $dom = $self->{dom} ||= Mojo::DOM->new($self->text);
return @_ ? $dom->find(@_) : $dom;
}

Expand Down Expand Up @@ -195,6 +188,13 @@ sub parse {

sub start_line_size { length shift->build_start_line }

sub text {
my $self = shift;
my $content = $self->body;
my $charset = $self->content->charset;
return $charset ? decode($charset, $content) // $content : $content;
}

sub to_string {
my $self = shift;
return $self->build_start_line . $self->build_headers . $self->build_body;
Expand Down Expand Up @@ -473,13 +473,6 @@ it should not be called before all headers have been received.
Access message cookies. Meant to be overloaded in a subclass.
=head2 decoded_body
my $str = $msg->decoded_body;
Slurp C<content> and try to decode it if a charset could be extracted with
L<Mojo::Content/"charset">.
=head2 dom
my $dom = $msg->dom;
Expand Down Expand Up @@ -609,6 +602,13 @@ Parse message chunk.
Size of the start line in bytes.
=head2 text
my $str = $msg->text;
Retrieve C<body> and try to decode it if a charset could be extracted with
L<Mojo::Content/"charset">.
=head2 to_string
my $str = $msg->to_string;
Expand Down
12 changes: 6 additions & 6 deletions lib/Test/Mojo.pm
Expand Up @@ -38,25 +38,25 @@ sub app {
sub content_is {
my ($self, $value, $desc) = @_;
$desc ||= 'exact match for content';
return $self->_test('is', $self->tx->res->decoded_body, $value, $desc);
return $self->_test('is', $self->tx->res->text, $value, $desc);
}

sub content_isnt {
my ($self, $value, $desc) = @_;
$desc ||= 'no match for content';
return $self->_test('isnt', $self->tx->res->decoded_body, $value, $desc);
return $self->_test('isnt', $self->tx->res->text, $value, $desc);
}

sub content_like {
my ($self, $regex, $desc) = @_;
$desc ||= 'content is similar';
return $self->_test('like', $self->tx->res->decoded_body, $regex, $desc);
return $self->_test('like', $self->tx->res->text, $regex, $desc);
}

sub content_unlike {
my ($self, $regex, $desc) = @_;
$desc ||= 'content is not similar';
return $self->_test('unlike', $self->tx->res->decoded_body, $regex, $desc);
return $self->_test('unlike', $self->tx->res->text, $regex, $desc);
}

sub content_type_is {
Expand Down Expand Up @@ -490,7 +490,7 @@ Access application with L<Mojo::UserAgent/"app">.
$t = $t->content_is('working!', 'right content');
Check response content for exact match after retrieving it from
L<Mojo::Message/"decoded_body">.
L<Mojo::Message/"text">.
=head2 content_isnt
Expand All @@ -505,7 +505,7 @@ Opposite of C<content_is>.
$t = $t->content_like(qr/working!/, 'right content');
Check response content for similar match after retrieving it from
L<Mojo::Message/"decoded_body">.
L<Mojo::Message/"text">.
=head2 content_unlike
Expand Down

0 comments on commit 0ad8bf8

Please sign in to comment.