+# Get CAS handler and service URI
+sub _get_cas_and_service {
+ my $query = shift;
+ my $key = shift; # optional
+
+ my $uri = _url_with_get_params($query);
+
+ my $casparam = $defaultcasserver;
+ $casparam = $query->param('cas') if defined $query->param('cas');
+ $casparam = $key if defined $key;
+ my $cas = Authen::CAS::Client->new( $casservers->{$casparam} );
+
+ return ( $cas, $uri );
+}
+
+# Get the current URL with parameters contained directly into URL (GET params)
+# This method replaces $query->url() which will give both GET and POST params
+sub _url_with_get_params {
+ my $query = shift;
+
+ my $uri_base_part = C4::Context->preference('OPACBaseURL') . $query->script_name();
+ my $uri_params_part = '';
+ foreach ( $query->url_param() ) {
+ # url_param() always returns parameters that were deleted by delete()
+ # This additional check ensure that parameter was not deleted.
+ if ($query->param($_)) {
+ $uri_params_part .= '&' if $uri_params_part;
+ $uri_params_part .= $_ . '=';
+ $uri_params_part .= URI::Escape::uri_escape( $query->param($_) );
+ }
+ }
+ $uri_base_part .= '?' if $uri_params_part;
+
+ return $uri_base_part . $uri_params_part;
+}