| Mozilla-Mechanize documentation | Contained in the Mozilla-Mechanize distribution. |
Mozilla::Mechanize::Image - Mimic WWW::Mechanize::Image
sorry, read the code for now
The Mozilla::Mechanize::Image object is a thin wrapper around
an image element.
Initialize a new object. $image_node is a Mozilla::DOM::HTMLElement (Mozilla::DOM::HTMLElement) (or a node that can be QueryInterfaced to one); specifically, it must be an HTMLImageElement or an HTMLInputElement whose type="image".
$moz is a Mozilla::Mechanize object. This is optional and currently unused.
Return the SRC attribute from the IMG tag.
Return 'IMG' for images.
Return the value of the width attribute. Only works for <img>.
Return the value of the height attribute. Only works for <img>.
Return the value alt attrubite.
Copyright 2005,2009 Scott Lanning <slanning@cpan.org>. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
| Mozilla-Mechanize documentation | Contained in the Mozilla-Mechanize distribution. |
package Mozilla::Mechanize::Image; use strict; use warnings; # $Id: Image.pm,v 1.3 2005/10/07 12:17:24 slanning Exp $
sub new { my $class = shift; my $node = shift; my $moz = shift; my $iid = 0; if (lc $node->GetNodeName eq 'img') { $iid = Mozilla::DOM::HTMLImageElement->GetIID; } elsif (lc $node->GetNodeName eq 'input') { $iid = Mozilla::DOM::HTMLInputElement->GetIID; # type="image" } else { my $errstr = "Invalid Image node"; defined($moz) ? $moz->die($errstr) : die($errstr); } my $image = $node->QueryInterface($iid); my $self = { image => $image }; $self->{moz} = $moz if defined $moz; bless($self, $class); }
sub url { my $self = shift; my $img = $self->{image}; return $img->GetSrc; }
sub tag { my $self = shift; my $img = $self->{image}; return $img->GetTagName; }
sub width { my $self = shift; my $img = $self->{image}; if (lc($self->tag) eq 'img') { # xxx: no! #return $img->GetWidth; return $img->GetAttribute('width'); } else { return ''; } }
sub height { my $self = shift; my $img = $self->{image}; if (lc($self->tag) eq 'img') { # xxx: no! #return $img->GetHeight; return $img->GetAttribute('height'); } else { return ''; } }
sub alt { my $self = shift; my $img = $self->{image}; return $img->GetAlt; } 1; __END__