Gossamer Forum
Home : General : Perl Programming :

GT Module and SCALAR tags

Quote Reply
GT Module and SCALAR tags
I am using the GT::Mail::POP3 module to hit a POP3 server and verify if a user (and correct password) exist on the server. It is currently setup as a global variable. Here is the code:

sub {
# ------------------------------------------------------------------
# Used to check the Mail server for new messages.
#
use GT::Mail::POP3;
my $tags = GT::Template->tags;

my $id = $tags->{"chpdcmail"};
$id =~ s/\s+$//;

my $password = $tags->{"Password"};
$password =~ s/\s+$//;

open(OLD_STDERR,">&STDERR") or die "Failed to save STDERR";
open(STDERR,">script.err") or die "Failed to redirect STDERR";

# Constructors
my $pop = new GT::Mail::POP3 (
host => 'mail.alliedhealthsystems.com',
port => 110,
user => $id,
pass => $password,
auth_mode => 'PASS',
Timeout => '5',
debug => 1
);

my $count = $pop->connect;

if($count > 0) {
$tags->{home}->{sql}->table('Claims_Users')->update ( { SamePass => '1'}, { Username => $tags->{Username}} );
}
else { $tags->{home}->{sql}->table('Claims_Users')->update ( { SamePass => '0'}, { Username => $tags->{Username}} ); }

$pop->quit;

open(STDERR,">&OLD_STDERR") or die "Failed to restore STDERR";

return $count;
}

When I run the script, it runs correctly but never does what you expect. I captured the STDERR from the script and this is what I got:

GT::Mail::POP3 (6682): Attempting to connect .. at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 215.
GT::Mail::POP3 (6682): Connected to mail.alliedhealthsystems.com on port 110 at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 233.
GT::Mail::POP3 (6682): Going to login at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 241.
GT::Mail::POP3 (6682): Attempting to log in via clear text ... at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 288.
GT::Mail::POP3 (6682): --> USER SCALAR(0x97c65e0) at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 154.
GT::Mail::POP3 (6682): <-- +OK SCALAR(0x97c65e0) at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 163.
GT::Mail::POP3 (6682): --> PASS admin at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 154.
GT::Mail::POP3 (6682): <-- -ERR Unknown user or incorrect password at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 163.
GT::Mail::POP3 (6682): An error occured while logging in: PASS POP Login failed: -ERR Unknown user or incorrect password at (eval 24) line 31.
GT::Mail::POP3 (6682): --> QUIT at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 154.
GT::Mail::POP3 (6682): <-- +OK mail.alliedhealthsystems.com closing connection at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 163.

So basically I see the problem... It is sending the text "SCALAR(0x97c65e0)" as the username (and probably the password). Which obviously the mailserver does not understand. So how do I get it to send the actual value of the variable and not the scalar reference???
Quote Reply
Re: [LanceWilson2] GT Module and SCALAR tags In reply to
Hi,

I've got a feeling its something to do with your line:

Code:
my $tags = GT::Template->tags;

Try using:

Code:
my $tags = shift;

You could also try writing out some debug info:

Code:
print STDERR qq|
-----------------------
DEBUG:
user => $id,
pass => $password,
-----------------------
|;

Basically, SCALAR(xxxx) normally means that the hashref isn't formed correctly.

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] GT Module and SCALAR tags In reply to
Thank you for your quick reply... I appreciate it. I did what you suggested (because I don't know what else to try) and it still did not work. Here is what I got:

Code:

-----------------------
DEBUG: user => SCALAR(0xa251700),
pass => SCALAR(0xa25179c),
-----------------------
GT::Mail::POP3 (24229): Attempting to connect .. at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 215.
GT::Mail::POP3 (24229): Connected to mail.alliedhealthsystems.com on port 110 at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 233.
GT::Mail::POP3 (24229): Going to login at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 241.
GT::Mail::POP3 (24229): Attempting to log in via clear text ... at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 288.
GT::Mail::POP3 (24229): --> USER SCALAR(0xa251700) at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 154.
GT::Mail::POP3 (24229): <-- +OK SCALAR(0xa251700) at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 163.
GT::Mail::POP3 (24229): --> PASS SCALAR(0xa25179c) at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 154.
GT::Mail::POP3 (24229): <-- -ERR Unknown user or incorrect password at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 163.
GT::Mail::POP3 (24229): An error occured while logging in: PASS POP Login failed: -ERR Unknown user or incorrect password at (eval 24) line 38.
GT::Mail::POP3 (24229): --> QUIT at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 154.
GT::Mail::POP3 (24229): <-- +OK mail.alliedhealthsystems.com closing connection at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 163.


It is still sending the SCALAR value to the connection. Now I can place a specific username and password in the script like this and it work just file with the correct username and password. But this does me no good as I cannot hardcode different user settings.

Code:

# Constructors
my $pop = new GT::Mail::POP3 (
host => 'mail.alliedhealthsystems.com',
user => 'username',
pass => 'password',
timeout => '5',
debug => 1
);


Any further help would be most appreciated.
Quote Reply
Re: [LanceWilson2] GT Module and SCALAR tags In reply to
Hi,

Yeah, its still using the hashref as a string :/

Did you try the "shift" option, instead of GT::Template->tags ?

Also, what progam is this being used in? GMail, GLinks ?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [LanceWilson2] GT Module and SCALAR tags In reply to
Strings returned from GT::Template are usually string refs (which when used in the templates means that they aren't html escaped), so you need to dereference them. Do something like:
my $id = ${$tags->{chpdcmail}};

Adrian
Quote Reply
Re: [brewt] GT Module and SCALAR tags In reply to
In Reply To:
Strings returned from GT::Template are usually string refs (which when used in the templates means that they aren't html escaped), so you need to dereference them. Do something like:
my $id = ${$tags->{chpdcmail}};

hah ha. I would never have worked that out <G>

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [brewt] GT Module and SCALAR tags In reply to
Yes!!!! That did it. I would never have worked that out either. PERL can sometimes be a blessing and a curse. Took me at least a week of searching around. I'm glad I posted the question here. Thank you!
Quote Reply
Re: [LanceWilson2] GT Module and SCALAR tags In reply to
In Reply To:
I would never have worked that out either. PERL can sometimes be a blessing and a curse. Took me at least a week of searching around.
Indeed - the best way of learning some of the "odd" things in Perl, is by gurus <G> (yeah, I'm talking about you Adrian Wink

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!