Skip to content

Commit 0c76b91

Browse files
sjohnstonsimbabque
authored andcommitted
move reused code into _uri_with_base method
1 parent d5414cb commit 0c76b91

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

lib/WWW/Mechanize.pm

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -476,11 +476,7 @@ sub get {
476476
my $self = shift;
477477
my $uri = shift;
478478

479-
$uri = $uri->url if ref($uri) eq 'WWW::Mechanize::Link';
480-
481-
$uri = $self->base
482-
? URI->new_abs( $uri, $self->base )
483-
: URI->new( $uri );
479+
$uri = $self->_uri_with_base( $uri );
484480

485481
# It appears we are returning a super-class method,
486482
# but it in turn calls the request() method here in Mechanize
@@ -499,11 +495,7 @@ sub post {
499495
my $self = shift;
500496
my $uri = shift;
501497

502-
$uri = $uri->url if ref($uri) eq 'WWW::Mechanize::Link';
503-
504-
$uri = $self->base
505-
? URI->new_abs( $uri, $self->base )
506-
: URI->new( $uri );
498+
$uri = $self->_uri_with_base( $uri );
507499

508500
# It appears we are returning a super-class method,
509501
# but it in turn calls the request() method here in Mechanize
@@ -525,11 +517,7 @@ sub put {
525517
my $self = shift;
526518
my $uri = shift;
527519

528-
$uri = $uri->url if ref($uri) eq 'WWW::Mechanize::Link';
529-
530-
$uri = $self->base
531-
? URI->new_abs( $uri, $self->base )
532-
: URI->new( $uri );
520+
$uri = $self->_uri_with_base( $uri );
533521

534522
# It appears we are returning a super-class method,
535523
# but it in turn calls the request() method here in Mechanize
@@ -557,15 +545,24 @@ sub head {
557545
my $self = shift;
558546
my $uri = shift;
559547

548+
$uri = $self->_uri_with_base( $uri );
549+
550+
# It appears we are returning a super-class method,
551+
# but it in turn calls the request() method here in Mechanize
552+
return $self->SUPER::head( $uri->as_string, @_ );
553+
}
554+
555+
sub _uri_with_base {
556+
my $self = shift;
557+
my $uri = shift;
558+
560559
$uri = $uri->url if ref($uri) eq 'WWW::Mechanize::Link';
561560

562561
$uri = $self->base
563562
? URI->new_abs( $uri, $self->base )
564563
: URI->new( $uri );
565564

566-
# It appears we are returning a super-class method,
567-
# but it in turn calls the request() method here in Mechanize
568-
return $self->SUPER::head( $uri->as_string, @_ );
565+
return $uri;
569566
}
570567

571568
=head2 $mech->reload()

0 commit comments

Comments
 (0)