X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDOM%2FTiny.pm;h=5e20917a6e664c893360a3c3993fdb1e7645b556;hb=3793c28fc8d722efd6bfff60020926bebedd03e5;hp=84dfeeafff9901f2be233737e667e7a10ca61a16;hpb=927f135111d601e084c5a50e2d806bddd5c9cefb;p=catagits%2FDOM-Tiny.git diff --git a/lib/DOM/Tiny.pm b/lib/DOM/Tiny.pm index 84dfeea..5e20917 100644 --- a/lib/DOM/Tiny.pm +++ b/lib/DOM/Tiny.pm @@ -18,6 +18,12 @@ use Scalar::Util qw(blessed weaken); our $VERSION = '0.001'; +sub new { + my $class = shift; + my $self = bless \DOM::Tiny::HTML->new, ref $class || $class; + return @_ ? $self->parse(@_) : $self; +} + sub all_text { shift->_all_text(1, @_) } sub ancestors { _select($_[0]->_collect($_[0]->_ancestors), $_[1]) } @@ -97,12 +103,6 @@ sub namespace { return undef; } -sub new { - my $class = shift; - my $self = bless \DOM::Tiny::HTML->new, ref $class || $class; - return @_ ? $self->parse(@_) : $self; -} - sub next { $_[0]->_maybe($_[0]->_siblings(1, 0)->[1]) } sub next_node { $_[0]->_maybe($_[0]->_siblings(0, 0)->[1]) } @@ -164,10 +164,8 @@ sub type { shift->tree->[0] } sub val { my $self = shift; - my $tag = $self->tag; - # "option" - return defined $self->{value} ? $self->{value} : $self->text if $tag eq 'option'; + return $self->{value} // $self->text if (my $tag = $self->tag) eq 'option'; # "textarea", "input" or "button" return $tag eq 'textarea' ? $self->text : $self->{value} if $tag ne 'select'; @@ -482,6 +480,14 @@ XML detection can also be disabled with the L method. L implements the following methods. +=head2 new + + my $dom = DOM::Tiny->new; + my $dom = DOM::Tiny->new('I ♥ DOM::Tiny!'); + +Construct a new scalar-based L object and L HTML/XML +fragment if necessary. + =head2 all_text my $trimmed = $dom->all_text; @@ -711,14 +717,6 @@ Find this element's namespace or return C if none could be found. # Find namespace for an element that may or may not have a namespace prefix my $namespace = $dom->at('svg > circle')->namespace; -=head2 new - - my $dom = DOM::Tiny->new; - my $dom = DOM::Tiny->new('I ♥ DOM::Tiny!'); - -Construct a new scalar-based L object and L HTML/XML -fragment if necessary. - =head2 next my $sibling = $dom->next;