marky1124 has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I am looking for some wisdom to understand what to do regarding a prototype mismatch between a couple of modules that I need to use.

This is the code

#!/usr/bin/perl -w use strict; use CGI::Fast qw(:standard); #use CGI::Fast; use URI::URL; my $key = param('key');

Running this gives the following

Prototype mismatch: sub main::url: none vs ($;$) at /usr/share/perl/5.10/Exporter.pm line 67. at /tmp/try.pl line 6

I can get rid of the Prototype mismatch message if I change to 'use CGI::Fast;' but then the code reports 'Undefined subroutine &main::param called at /tmp/try.pl line 8.'

I have the latest versions of these modules from CPAN (URI::URL v5.04 and CGI::Fast v1.09)

I'm unsure how to resolve this, I look forward to basking in your wisdom

All the best

Mark

Replies are listed 'Best First'.
Re: Resolving Prototype mismatch
by Anonymous Monk on Aug 09, 2012 at 10:53 UTC

    use CGI ':standard'; exports url

    use URI::URL; exports url

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

      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'

        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