Mozilla::Mechanize::Image - Mimic L<WWW::Mechanize::Image>


Mozilla-Mechanize documentation Contained in the Mozilla-Mechanize distribution.

Index


Code Index:

NAME Mozilla::Mechanize::Image

Top

Mozilla::Mechanize::Image - Mimic WWW::Mechanize::Image

SYNOPSIS

Top

sorry, read the code for now

DESCRIPTION

Top

The Mozilla::Mechanize::Image object is a thin wrapper around an image element.

METHODS

Top

Mozilla::Mechanize::Image->new($image_node, $moz)

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.

$image->url

Return the SRC attribute from the IMG tag.

$image->tag

Return 'IMG' for images.

$image->width

Return the value of the width attribute. Only works for <img>.

$image->height

Return the value of the height attribute. Only works for <img>.

$image->alt

Return the value alt attrubite.

COPYRIGHT AND LICENSE

Top


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__