[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



On Thu, Jun 24, 2010 at 11:57 AM, Dan Linder <dan@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=||