Date: | Sat, 13 Dec 2003 05:01:43 -0800 |
Subject: | feature request, WWW::Mech::Link returns absolute URI on request |
From: | apv <ashley [...] sedition.com> |
To: | bug-www-mechanize [...] rt.cpan.org |
Feature request forwarded for formal tracking. Thank you for looking at
it!
From: apv <ashley@sedition.com>
Date: Fri Dec 12, 2003 2:40:48 AM US/Pacific
To: andy@petdance.com
Subject: you rock
Dear Andy,
WWW::Mechanize is just terrific. Seriously. A sanity saver. I feel my
carpal tunnel improving already.
Now that I've complimented you, sufficiently I hope, I'll beg for a
feature.
Absolute URIs back from link objects. I realize this would add some
memory and process overhead and might not be desirable but I would use
it and I imagine others might.
The WWW::Mechanize::Link constructor could become
use URI;
sub new {
my $class = shift;
my $url = shift;
my $text = shift;
my $name = shift;
my $tag = shift;
my $base = shift; #<<--new
my $self = [$url,$text,$name,$tag,$base];
bless $self, $class;
return $self;
}
# new ::Link sub could be something along these lines
sub abs_url {
my ( $self ) = @_;
my $uri = $self->[4] ?
URI->new_abs( $self->[0], $self->[4] )
: URI->new( $self->[0] );
return $uri->as_string;
}
And then in WWW::Mechanize proper (around line 1307):
next unless defined $url; # [your comment]
my $base = $self->base;
my $link = WWW::Mechanize::Link->new
( $url, $text, $name, $tag, $base )
push( @{$self->{links}}, $link;
That code, please forgive me, is untested but I didn't want to ask
without having something to show.
Thank you for the great module and for your time either way.
-Ashley
On Friday, December 12, 2003, at 06:48 PM, Andy Lester wrote:
Show quoted text
>> # new ::Link sub could be something along these lines
>> sub abs_url {
>> my ( $self ) = @_;
>> my $uri = $self->[4] ?
>> URI->new_abs( $self->[0], $self->[4] )
>> : URI->new( $self->[0] );
>> return $uri->as_string;
>> }
>
> Shouldn't be a problem. Can you please resend your message to
> bug-www-mechanize@rt.cpan.org so I can track the ticket?
>
> Thanks,
> xoa
>
> --
> Andy Lester
> andy@petdance.com, AIM:petdance
> http://petdance.com/ http://use.perl.org/~petdance/
>
>