Skip Menu |
 

This queue is for tickets about the HTML-Tree CPAN distribution.

Report information
The Basics
Id: 83483
Status: rejected
Priority: 0/
Queue: HTML-Tree

People
Owner: Nobody in particular
Requestors: david [...] davidfavor.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: HTML:::Element $obj->pos() seems to have no effect
Date: Wed, 20 Feb 2013 11:52:45 -0600
To: bug-html-tree [...] rt.cpan.org
From: David Favor <david [...] davidfavor.com>
Download (untitled) / with headers
text/plain 522b
Please update documentation to have an example of how to use $obj->pos() to have $obj->insert_element() insert a new HTML::Element object as the first child of a parent, rather than the last child. For example, how to insert: my $obj = HTML::Element->new('meta', 'charset' => $charset); as the first child of the <head> tag, rather than the last. Please hit reply also and let me know how to do this. Thanks. -- Love feeling your best ever, all day, every day? Click http://RadicalHealth.com for the easy way!
Download (untitled) / with headers
text/plain 558b
insert_element doesn't work that way. It's intended as a convenience method when building a tree from a stream of parsing events. The pos() indicates which element the new one gets appended to, not the position among that element's children (it's always the last child). I think you're looking for the unshift_content method. my $obj = HTML::Element->new('meta', 'charset' => $charset); $html->look_down(qw(_tag head))->unshift_content($obj); Or just $html->look_down(qw(_tag head))->unshift_content( [ meta => { charset => $charset } ] );
Subject: Re: [rt.cpan.org #83483] HTML:::Element $obj->pos() seems to have no effect
Date: Mon, 25 Feb 2013 10:50:16 -0600
To: bug-HTML-Tree [...] rt.cpan.org
From: David Favor <david [...] davidfavor.com>
Download (untitled) / with headers
text/plain 810b
Christopher J. Madsen via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=83483 > > > insert_element doesn't work that way. It's intended as a convenience > method when building a tree from a stream of parsing events. The pos() > indicates which element the new one gets appended to, not the position > among that element's children (it's always the last child). > > I think you're looking for the unshift_content method. > > my $obj = HTML::Element->new('meta', 'charset' => $charset); > $html->look_down(qw(_tag head))->unshift_content($obj); > > Or just > > $html->look_down(qw(_tag head))->unshift_content( > [ meta => { charset => $charset } ] > ); >
Perfect! Thanks! -- Love feeling your best ever, all day, every day? Click http://RadicalHealth.com for the easy way!


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.