Skip to content

Instantly share code, notes, and snippets.

@marcusramberg
Created September 25, 2010 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcusramberg/596843 to your computer and use it in GitHub Desktop.
Save marcusramberg/596843 to your computer and use it in GitHub Desktop.
diff --git a/lib/Mojo/Message.pm b/lib/Mojo/Message.pm
index 2b12ec2..60f2576 100644
--- a/lib/Mojo/Message.pm
+++ b/lib/Mojo/Message.pm
@@ -240,7 +240,15 @@ sub dom {
and $charset = $1;
# Parse
- return $class->new(charset => $charset)->parse($self->body);
+ my $dom=$class->new(charset => $charset)->parse($self->body);
+
+ # Shortcut for find?
+ my $selector=shift;
+ if (defined $selector) {
+ return $dom->find($selector);
+ }
+
+ return $dom;
}
sub error {
@@ -784,8 +792,10 @@ Access message cookies.
=head2 C<dom>
my $dom = $message->dom;
+ my $res = $message->dom('a');
-Parses content into a L<Mojo::DOM> object.
+Parses content into a L<Mojo::DOM> object. Take an optional selector
+to perform a find on the dom directly.
Note that this method is EXPERIMENTAL and might change without warning!
=head2 C<error>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment