use Exporter;
-our $VERSION = '1.0.20';
+our $VERSION = '1.0.21';
our @ISA = qw(Exporter);
our @EXPORT = ();
our @EXPORT_OK = (
# ".." in the path is not resolved so "/aaa/bbb" + "../ccc" will be
# "/aaa/bbb/../ccc" and not "/aaa/ccc". TODO: improve?
sub merge_url {
- (my $base_url, my $target_url) = @_;
- my %base_data;
- my %target_data;
- my %final_data;
- my $final_url;
- if (ref($base_url)) {
- %base_data = %$base_url;
- }
- else {
- %base_data = split_url($base_url);
- }
- if (ref($target_url)) {
- %target_data = %$target_url;
- }
- else {
- %target_data = split_url($target_url, 1);
- }
-
- if (
- ($target_data{'scheme'} ne '') or
- ($target_data{'authority'} ne '') or
- ($target_data{'host'} ne '')
- ) {
- return join_url(\%target_data);
- }
-
- $final_data{'scheme'} = $base_data{'scheme'};
- $final_data{'authority'} = $base_data{'authority'};
- $final_data{'host'} = $base_data{'host'};
- $final_data{'port'} = $base_data{'port'};
- $final_data{'userinfo'} = $base_data{'userinfo'};
- $final_data{'path'} = $base_data{'path'};
- $final_data{'query'} = $base_data{'query'};
- $final_data{'fragment'} = $base_data{'fragment'};
-
- if ($target_data{'path'} ne '') {
- $final_data{'path'} = join_path('/', $base_data{'path'}, $target_data{'path'});
- $final_data{'query'} = '';
- $final_data{'fragment'} = '';
- }
-
- if ($target_data{'query'} ne '') {
- $final_data{'query'} = $target_data{'query'};
- $final_data{'fragment'} = '';
- }
-
- if ($target_data{'fragment'} ne '') {
- $final_data{'fragment'} = $target_data{'fragment'};
+ (my $base_url, my @target_urls) = @_;
+
+ foreach my $target_url (@target_urls) {
+ my %base_data;
+ my %target_data;
+ my %final_data;
+ if (ref($base_url)) {
+ %base_data = %$base_url;
+ }
+ else {
+ %base_data = split_url($base_url);
+ }
+ if (ref($target_url)) {
+ %target_data = %$target_url;
+ }
+ else {
+ %target_data = split_url($target_url, 1);
+ }
+
+ if (
+ ($target_data{'scheme'} ne '') or
+ ($target_data{'authority'} ne '') or
+ ($target_data{'host'} ne '')
+ ) {
+ $base_url = join_url(\%target_data);
+ next;
+ }
+
+ $final_data{'scheme'} = $base_data{'scheme'};
+ $final_data{'authority'} = $base_data{'authority'};
+ $final_data{'host'} = $base_data{'host'};
+ $final_data{'port'} = $base_data{'port'};
+ $final_data{'userinfo'} = $base_data{'userinfo'};
+ $final_data{'path'} = $base_data{'path'};
+ $final_data{'query'} = $base_data{'query'};
+ $final_data{'fragment'} = $base_data{'fragment'};
+
+ if ($target_data{'path'} ne '') {
+ $final_data{'path'} = join_path('/', $base_data{'path'}, $target_data{'path'});
+ $final_data{'query'} = '';
+ $final_data{'fragment'} = '';
+ }
+
+ if ($target_data{'query'} ne '') {
+ $final_data{'query'} = $target_data{'query'};
+ $final_data{'fragment'} = '';
+ }
+
+ if ($target_data{'fragment'} ne '') {
+ $final_data{'fragment'} = $target_data{'fragment'};
+ }
+
+ $base_url = join_url(\%final_data);
}
-
- return join_url(\%final_data);
+ return $base_url;
}
# URL query string