[cgiapp] Losing params - wtf is wrong??

Joshua Miller unrtst at gmail.com
Sat Aug 16 19:25:56 EDT 2008


Mark,

In your code, you're setting the profile param as:
    $session->param(profile => {ticket => $ticket,
                                nick => $nick,
                                group => $groups_member});

Later, you bless it thusly:
    my $profile = bless $self->param('profile');

And then use attempt to use it like so:
    $template->param(USER => $profile->param('nick'));

You're assuming that will get the data item "nice" that was initial set
in the hash ref assigned to the "profile" param.

The bless you added blesses the reference into the current class (based
on the log, I'm assuming that is LDAP::Login, and I'm going to assume
that LDAP::Login inherits from CGI::Application).

CGI::Application does indeed have a ->param() method, so the method call
works, but it's not returning the data for "nick" when called. This is
because you set "nick" as part of a normal hash ref, and did not use
the accessor method to set it. If you look in the Data::Dumper output
from the template output, you'll see:

profile object: profile object $VAR1 = bless( {
 'group' => 'postini-scm',
 '__PARAMS' => {},
 'nick' => 'mjaffe',
 'ticket' => '1|mjaffe|google.com
|GSSOpstnDBrfa|20080815224748|password|LDAP|1000000|postini-scm|dsa|E+R|MC0CFQCXXVaQsECi4j9GzCqcggMFOoiV8wIUIcCcTC0escDCdUTsZYv20ttypYs='
}, 'LDAP::Login' );

Notice the '__PARAMS' key. That's where CGI::Application would normally
store it's params when set through the ->param() method. There's
nothing there, and that's where "nick" needs to be in order for
->param('nick') to find that value.


So, change the part that populates $self->param('profile') to be:
    my $profile = bless({});
    $profile->param( ticket => $ticket );
    $profile->param( nick => $nick );
    $profile->param( group => $groups_member );
    $session->param(profile => $profile);

And remove the call to bless that you have in processtmpl().

As an alternative, you could just not bless it, and access the variables
directly when you need them. IE, in processtmpl():
        $template->param(USER => $profile->{'nick'});
This way, it's just a plain old hashref.

Hope that helps,
--
Josh I.


On Sat, Aug 16, 2008 at 5:14 PM, Mark Jaffe <jaffe.mark at gmail.com> wrote:

> Ron,
>
> I've updated the snippet page at http://71.202.190.49/~mjaffe/CGI-app.log<http://71.202.190.49/%7Emjaffe/CGI-app.log>;
> it now shows how the data is set in the "profile". The single-arg method is
> used because the "profile" has no associated class. I added the "bless" when
> I got an error "Can't call method "param" on unblessed reference at
> LDAP/Login.pm line 122," when the code looked like this:
>
>   if ( $self->param('profile') ) {
>      if ( $self->param("profile")->param('ticket') ) {
>           $template->param(USER => $self->param("profile")->param('nick'));
>           $template->param(GROUP
> =>$self->param("profile")->param('group'));
>       }
>   }
> This code is somewhat based on an example found here:
> http://cgi-app.org/index.cgi?LoginLogoutExampleApp
>
> Mark
>
>


More information about the cgiapp mailing list