Update of /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19555/lib/OpenInteract2
Modified Files:
URL.pm
Log Message:
add 'add_params_to_url()' to OI2::URL and a pointer to it from OI2::TT2::Plugin; plus tests
Index: URL.pm
===================================================================
RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/URL.pm,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** URL.pm 4 Oct 2004 12:54:32 -0000 1.25
--- URL.pm 24 Nov 2004 14:16:01 -0000 1.26
***************
*** 128,136 ****
return $url_base unless ( scalar keys %{ $params } );
my $query = join( QUERY_ARG_SEPARATOR,
map { _url_escape( $_ ) . "=" . _url_escape( $params->{ $_ } ) }
grep { defined $params->{ $_ } }
keys %{ $params } );
! return "$url_base?$query";
}
--- 128,143 ----
return $url_base unless ( scalar keys %{ $params } );
+ return $class->add_params_to_url( $url_base, $params );
+ }
+
+ sub add_params_to_url {
+ my ( $class, $url, $params ) = @_;
my $query = join( QUERY_ARG_SEPARATOR,
map { _url_escape( $_ ) . "=" . _url_escape( $params->{ $_ } ) }
grep { defined $params->{ $_ } }
keys %{ $params } );
! return ( $url =~ /\?/ )
! ? join( QUERY_ARG_SEPARATOR, $url, $query )
! : "$url?$query";
}
***************
*** 516,519 ****
--- 523,547 ----
# $url = '/cgi-bin/oi.cgi/Public/Foo/detail/?name=Mario%20Lemieux'
+ C<add_params_to_url( $url, \%params )>
+
+ Adds the escaped key/value pairs in C<\%params> as GET parameters to
+ C<$url>, which is assumed to be contextualized and escaped already.
+
+ So:
+
+ my $url = '/foo/bar';
+ my %params = ( id => '55', undercover => 'yes' );
+ my $url_with_params = OpenInteract2::URL->add_params_to_url( $url, \%params );
+ # $url_with_params = '/foo/bar?id=55&undercover=yes
+
+ The method can detect if you've already got query parameters in your
+ url:
+
+
+ my $url = '/foo/bar?keep=no';
+ my %params = ( id => '55', undercover => 'yes' );
+ my $url_with_params = OpenInteract2::URL->add_params_to_url( $url, \%params );
+ # $url_with_params = '/foo/bar?keep=no&id=55&undercover=yes
+
=head1 SEE ALSO
|