Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Getting list of available values in my (@args) = @_;

Quote Reply
Getting list of available values in my (@args) = @_;
At the beginning of a plugin hook sub, you can get the args by putting this code in there:

Code

sub user_signup {
# -------------------------------------------------------------------
# This subroutine will get called whenever the hook 'user_signup'
# is run. You should call GT::Plugins->action ( STOP ) if you don't
# want the regular code to run, otherwise the code will continue as
# normal.
#
my (@args) = @_





I have no idea what type of data structure this is. Can someone tell me what type of data structure it is and how to print out the list of all the arguements please?

Thanks for your assistance.

Last edited by:

giovanni: Aug 4, 2002, 10:55 AM
Quote Reply
Re: [giovanni] Getting list of available values in my (@args) = @_; In reply to
Answer: %{$args[0]}
Quote Reply
Re: [giovanni] Getting list of available values in my (@args) = @_; In reply to
>>
Answer: %{$args[0]}
<<

....that will only work if the argument is a hashref otherwise you'll get an error, your best bet is to use GT::Dumper....

require GT::Dumper;

print Dumper(\@args);

Last edited by:

Paul: Aug 4, 2002, 11:08 AM
Quote Reply
Re: [Paul] Getting list of available values in my (@args) = @_; In reply to
Thanks for your help paul. I am still having problems as the first bit of code didn't work and the below doesn't work either. I will try your code now.



sub user_signup {
# -------------------------------------------------------------------
# This subroutine will get called whenever the hook 'user_signup'
# is run. You should call GT::Plugins->action ( STOP ) if you don't
# want the regular code to run, otherwise the code will continue as
# normal.
#
my $arg1 = shift;
my $arg2 = shift;
my $arg3 = shift;

GT::Plugins->action ( STOP );
print $IN->header();
my $arg;

;

print qq|

$arg1 $arg2 $arg3

|;

}

Last edited by:

giovanni: Aug 4, 2002, 11:17 AM
Quote Reply
Re: [Paul] Getting list of available values in my (@args) = @_; In reply to
Encountered this problem:

A fatal error has occured:


ARRAY (1144): Unknown method 'Dumper' called at ....


with this code:



sub user_signup {
# -------------------------------------------------------------------
# This subroutine will get called whenever the hook 'user_signup'
# is run. You should call GT::Plugins->action ( STOP ) if you don't
# want the regular code to run, otherwise the code will continue as
# normal.
#
my (@args) = @_;GT::Plugins->action ( STOP );
print $IN->header();
require GT::Dumper; print Dumper(\@args); }

Last edited by:

giovanni: Aug 4, 2002, 11:21 AM
Quote Reply
Re: [Paul] Getting list of available values in my (@args) = @_; In reply to
This didn't really help, but is relevant:

http://www.gossamer-threads.com/p/198984
Quote Reply
Re: [giovanni] Getting list of available values in my (@args) = @_; In reply to
Try changing print Dumper(\@args);

...to...

print GT::Dumper::Dumper(\@args);
Quote Reply
Re: [Paul] Getting list of available values in my (@args) = @_; In reply to
Thanks Paul. All I got was:

Code:


$VAR = [];
Quote Reply
Re: [giovanni] Getting list of available values in my (@args) = @_; In reply to
i.e., I don't think that any arguments are being passed. Which is weird.
Quote Reply
Re: [giovanni] Getting list of available values in my (@args) = @_; In reply to
I will play with the pre/post stuff
Quote Reply
Re: [giovanni] Getting list of available values in my (@args) = @_; In reply to
When you ran the hook did you make an error in the signup form?...I made a plugin using that hook and there are no args if there is an error....if the signup is successful the arg is the new user details.

Last edited by:

Paul: Aug 4, 2002, 12:08 PM
Quote Reply
Re: [Paul] Getting list of available values in my (@args) = @_; In reply to
Hi Paul,

Thanks for your help.

The plugin doesn't allow users to sign up, it just checks if the username and password is available and then sends the user elsewhere. I need to run the plugin PRE FIRST so that I can get the valid, chosen username, password and email, and then pass it somewhere else.

There were no errors when filling out the form. Additionally, it seems that the plugin allows everthing to proceed even though it appears that there are no arguments.
Quote Reply
Re: [giovanni] Getting list of available values in my (@args) = @_; In reply to
am now using auth_valid_format instead
Quote Reply
Re: [giovanni] Getting list of available values in my (@args) = @_; In reply to
Okay, everything is okay now, in that I get the args from the param I think. But, now i get the error:



A fatal error has occured:
Can't use string ("1") as a HASH ref while "strict refs" in use at /home/....../admin/Links/Users.pm line 57.

Quote Reply
Re: [giovanni] Getting list of available values in my (@args) = @_; In reply to
You are trying to use a string as a hashref.
Quote Reply
Re: [giovanni] Getting list of available values in my (@args) = @_; In reply to
You are probably not returning the correct thing.

Try

return @args;

or something similar at the end of your sub.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [Paul] Getting list of available values in my (@args) = @_; In reply to
Thanks Paul. At the moment, my code looks like this, so I don't see how could be using the string as a hashref.



sub user_signup {
# -------------------------------------------------------------------

GT::Plugins->action ( STOP );

print $IN->header();

}

the hook I am using is auth_add_user

this is the relevant code in User.pm:

Code:


sub add {
# -------------------------------------------------------------------
# Add a user.
#
init();
my $self = shift;
my $p;
if (ref $_[0] eq 'HASH') { $p = $_[0]; }
else { $p = {@_}; }

if (! Links::Authenticate::auth ('valid_format', { Username => $p->{Username} })) {
return $self->error ('INVALIDFORMAT', 'WARN', $p->{Username});
}

my $h = Links::Authenticate::auth ('add_user', { Username => $p->{Username}, Password => $p->{Password} })
or return $self->error ('AUTHERROR', 'WARN', $Links::Authenticate::error);

-->HERE (Line 57)<-- $p->{Username} = $h->{Username};
$p->{Password} = $h->{Password};

return $self->SUPER::add($p);
}
Quote Reply
Re: [yogi] Getting list of available values in my (@args) = @_; In reply to
Hi Ivan,

At the moment I'm just trying to stop at the relevant point rather than return any values. Any ideas what would be causing the error?

Thanks for your help.
Quote Reply
Re: [Paul] Getting list of available values in my (@args) = @_; In reply to
Maybe it's impossible to stop the code at this point?
Quote Reply
Re: [giovanni] Getting list of available values in my (@args) = @_; In reply to
okay, all sorted now. I just needed to call exit.
Quote Reply
Re: [giovanni] Getting list of available values in my (@args) = @_; In reply to
You are stopping the code, but you still need to give the program back what it needs, i.e. a hashref containing at least the key "username".

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [giovanni] Getting list of available values in my (@args) = @_; In reply to
I wouldn't call that "sorted out". If you have to call exit, then you are probably doing something wrong, you may be using the wrong hook...

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Getting list of available values in my (@args) = @_; In reply to
Hi Yogi,

But if I return a value then Links SQL will go back to the normal page rather than the page that I want. It may be the wrong hook but if works perfectly. You are probably right, but I don't see how I'm meant to return a value and go to the page that I need to rather than the default one.