in reply to Resolving Prototype mismatch

use CGI ':standard'; exports url

use URI::URL; exports url

You can't have it both ways, pick which one you want

Replies are listed 'Best First'.
Re^2: Resolving Prototype mismatch
by marky1124 (Novice) on Aug 09, 2012 at 11:40 UTC

    Thanks for your reply. I'm not sure how to pick one when I need aspects of both modules. I think perhaps I overly simplified my example, so I have put together a more complete one which hopefully shows my dilemma. I want to use CGI::Fast to create a fast cgi daemon and I want to use URI::URL because it is used as part of the code to create a signed URL. Here's a better example of what I'm trying to do:

    #!/usr/bin/perl -w use strict; use CGI::Fast qw(:standard); use Digest::HMAC_SHA1; use MIME::Base64; use URI::URL; my ($key) = "0xc0dec0de"; my ($baseUrl) = "http://www.perlmonks.org/?node_id="; my ($url, $parsed_url, $url_to_sign, $node); my ($digest, $signature, $signed_url); while (new CGI::Fast) { $node = (defined param('node')) ? param('node') : '986481'; $url = $baseUrl . $node; $parsed_url = URI::URL->new($url); $url_to_sign = $parsed_url->path_query; $digest = Digest::HMAC_SHA1->new($key); $digest->add($url_to_sign); $signature = $digest->b64digest; $signed_url = $parsed_url->scheme .'://' . $parsed_url->host . $url_to_sign . '&signature=' . $signature; print " IN: $url\n"; print "OUT: $signed_url\n"; }

    Perhaps my best option is to parse the URL string myself, but ideally I don't want to do that since that's the sort of stuff which can be tricky to catch every corner case of unusual situations.

    Is it possible to request the two modules but exclude url from being exported in both cases?

    Cheers

    Mark

      Not this:

      use URI::URL;

      This instead:

      use URI::URL ();
      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

        Brilliant, thank you, that seems to have done it perfectly

        Can you tell me what you did there please?

        Cheers,

        Mark

      Thanks for your reply. I'm not sure how to pick one when I need aspects of both modules.

      Either you want the subroutine url from CGI or you want the subroutine url from URI::URL, you cannot have both under the name url

      Both are available under their full name, URI::URL::url() and CGI::url()

      Don't import subroutines you're not going to use

      Don't import subroutines that use the same name as some other suroutine you've imported

      You're using the CGI object-oriented interface, don't import :standard, it exports url into your namespace , among dozens of others function you don't use

      Read Simple Module Tutorial

        Thank you, that's very helpful. I understand it all so much more thoroughly now.

        Cheers,
        Mark