Skip to content

Commit

Permalink
more documentation and tests for Mojo::DOM
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 4, 2013
1 parent e25838a commit 1d21fef
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
21 changes: 13 additions & 8 deletions lib/Mojo/DOM.pm
Expand Up @@ -472,7 +472,8 @@ enabled by default.
$dom = $dom->append('<p>Hi!</p>');
Append to element.
Append HTML/XML to element. Note that the HTML/XML will be decoded if a
C<charset> has been defined.
# "<div><h1>A</h1><h2>B</h2></div>"
$dom->parse('<div><h1>A</h1></div>')->at('h1')->append('<h2>B</h2>')->root;
Expand All @@ -481,7 +482,8 @@ Append to element.
$dom = $dom->append_content('<p>Hi!</p>');
Append to element content.
Append HTML/XML to element content. Note that the HTML/XML will be decoded if
a C<charset> has been defined.
# "<div><h1>AB</h1></div>"
$dom->parse('<div><h1>A</h1></div>')->at('h1')->append_content('B')->root;
Expand Down Expand Up @@ -511,8 +513,7 @@ Element attributes.
my $charset = $dom->charset;
$dom = $dom->charset('UTF-8');
Charset used by C<parse>, C<content_xml> and C<to_xml> for decoding and
encoding HTML/XML.
Charset used for decoding and encoding HTML/XML.
=head2 children
Expand Down Expand Up @@ -592,7 +593,8 @@ be decoded if a C<charset> has been defined.
$dom = $dom->prepend('<p>Hi!</p>');
Prepend to element.
Prepend HTML/XML to element. Note that the HTML/XML will be decoded if a
C<charset> has been defined.
# "<div><h1>A</h1><h2>B</h2></div>"
$dom->parse('<div><h2>B</h2></div>')->at('h2')->prepend('<h1>A</h1>')->root;
Expand All @@ -601,7 +603,8 @@ Prepend to element.
$dom = $dom->prepend_content('<p>Hi!</p>');
Prepend to element content.
Prepend HTML/XML to element content. Note that the HTML/XML will be decoded if
a C<charset> has been defined.
# "<div><h2>AB</h2></div>"
$dom->parse('<div><h2>B</h2></div>')->at('h2')->prepend_content('A')->root;
Expand Down Expand Up @@ -629,7 +632,8 @@ Remove element and return it as a L<Mojo::DOM> object.
my $old = $dom->replace('<div>test</div>');
Replace element and return the replaced element as a L<Mojo::DOM> object.
Replace element and return the replaced element as a L<Mojo::DOM> object. Note
that the HTML/XML will be decoded if a C<charset> has been defined.
# "<div><h2>B</h2></div>"
$dom->parse('<div><h1>A</h1></div>')->at('h1')->replace('<h2>B</h2>')->root;
Expand All @@ -641,7 +645,8 @@ Replace element and return the replaced element as a L<Mojo::DOM> object.
$dom = $dom->replace_content('test');
Replace element content.
Replace element content with HTML/XML. Note that the HTML/XML will be decoded
if a C<charset> has been defined.
# "<div><h1>B</h1></div>"
$dom->parse('<div><h1>A</h1></div>')->at('h1')->replace_content('B')->root;
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/DOM/HTML.pm
Expand Up @@ -359,7 +359,7 @@ L<Mojo::DOM::HTML> implements the following attributes.
my $charset = $html->charset;
$html = $html->charset('UTF-8');
Charset used by C<parse> and C<render> for decoding and encoding HTML/XML.
Charset used for decoding and encoding HTML/XML.
=head2 tree
Expand Down
5 changes: 4 additions & 1 deletion t/mojo/dom.t
Expand Up @@ -332,7 +332,10 @@ is "$dom", '<p>foo</p><b>whatever</b><p>bar</p>', 'right result';
is $dom->find('p')->pluck('remove')->first->root->at('b')->text, 'whatever',
'right result';
is "$dom", '<b>whatever</b>', 'right result';
$dom->remove;
$dom->charset('UTF-8');
$dom->at('b')->replace_content(encode('UTF-8', ''));
is "$dom", encode('UTF-8', '<b>♥</b>'), 'right result';
$dom->charset(undef)->remove;
is "$dom", '', 'no result';

# Replace element content
Expand Down

0 comments on commit 1d21fef

Please sign in to comment.