[Omaha.pm] Accessing CGI objects passed through a function call...

Theodore Katseres tedkat at gmail.com
Thu Jun 24 10:13:06 PDT 2010


On Thu, Jun 24, 2010 at 11:57 AM, Dan Linder <dan at linder.org> wrote:

> I'm trying to access the Perl CGI modules self_url call in a function
> call.  Here's my code:
>
> === test001.pl ===
> #!/usr/bin/perl
> use lib ".";
> use CGI;
> use MyModule;
> my $cgi = CGI->new();
>
> show_my_link(\$cgi);
> exit;
> === end test001.pl ===
>
> My module is like this:
> === MyModule.pm ===
> package MyModule;
> use Exporter;
> @ISA = qw(Exporter);
> @EXPORT = qw(show_my_link);
>
> sub show_my_link {
>    my ($thecgi) = @_;
>    printf ("The full URL is: %s\n", $thecgi->self_url());
> }
> 1;
> === end MyModule.pm ===
>
> When I run the code above, I get the error:
>    Can't call method "self_url" on unblessed reference at MyModule.pm line
> 8.
> (Line 8 is the printf...self_url line.)
>
> I think I'm close, but is there something else I'm missing to make this
> call?
>

Best guess.

Pass the object not a reference to a scalar containing the object :)

show_my_link(\$cgi);
    should be
show_my_link($cgi);

-- 
Ted Katseres
     ||=O=||
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/omaha-pm/attachments/20100624/f5d402df/attachment.html>


More information about the Omaha-pm mailing list