[BEGINNER] Embperl question

S

soup_or_power

Can someone please explain this sub taken out of embperl code. I am not
sure what the Storable::thaw is doing.Many thanks!
sub get_session {
my ( $r ) = @_;

if ( ref $r eq 'Apache' ) {

# ------------------------------------------------
# session from Apache request
# ------------------------------------------------

my $cookie_head = $r->header_in('Cookie');
my $cookie_name = $ENV{EMBPERL_COOKIE_NAME} || 'EMBPERL_UID';
my ( $session_id ) = ($cookie_head =~
/$cookie_name=(.*?)(?:\;|\s|$)/);
my %args = &get_session_env();

my $dbh = DBI->connect(
$args{DataSource},
$args{UserName},
$args{Password},
{ RaiseError => 0, AutoCommit => 1 }
) || return undef;

my $session = $dbh->selectall_arrayref( q{
SELECT a_session
FROM sessions
WHERE id = ?
}, { }, $session_id );

$dbh->disconnect();

return ( defined $session && $session ) ? Storable::thaw(
$session->[0][0] ) : undef;
} else {

# ------------------------------------------------
# session from udat
# ------------------------------------------------

&session_synch( $r );

return %$r;
}
}
 
B

Brian McCauley

Can someone please explain this sub taken out of embperl code. I am not
sure what the Storable::thaw is doing.

Rather than showing us the code where Storable::thaw is called it would
perhaps be more productive if you showed us the part of the Storable
documentation that you are finding hard to follow.
 
S

soup_or_power

Brian said:
Rather than showing us the code where Storable::thaw is called it would
perhaps be more productive if you showed us the part of the Storable
documentation that you are finding hard to follow.

Sorry I didn't mean to be lazy. Let me break it down:
a)what is EMBPERL_SESSION_ARGS and where will one have to specify. Are
they configured into apache?
For example below:
sub get_session_env {
my %args;
foreach ( split( /\s+/, $ENV{EMBPERL_SESSION_ARGS} ) ) {
/^(.*?)\s*=\s*(.*?)$/;
$args{$1} = $2;
}

return %args;
}


b)what is $ENV{EMBPERL_COOKIE_NAME} and why can it be defaulted as
'EMBPERL_UID'

c)how exactly is $session_id extracted in the code?

d)how can one store the session in a database?

Bottom line is I couldn't find a book on embperl. If you can suggest a
book I'll be grateful.
Thanks
 
J

Juha Laiho

(e-mail address removed) said:
Sorry I didn't mean to be lazy. Let me break it down:
a)what is EMBPERL_SESSION_ARGS and where will one have to specify. Are
they configured into apache?

From Embperl documentation (comes with Embperl, readable with command
"perldoc HTML::Embperl"):

EMBPERL_SESSION_ARGS

List of arguments for Apache::Session classes (see "Session handling")
Arguments that contains spaces can be quoted. Example:

PerlSetEnv EMBPERL_SESSION_ARGS "DataSource=dbi:mysql:session UserName=www 'Password=secret word'"

For example below:
sub get_session_env {
my %args;
foreach ( split( /\s+/, $ENV{EMBPERL_SESSION_ARGS} ) ) {
/^(.*?)\s*=\s*(.*?)$/;
$args{$1} = $2;
}

return %args;
}

So, the above gets whatever is stored into the environment variable named
EMBPERL_SESSION_ARGS, and places them into a hash (and returns the hash).
With the above example, the hash would contain name-value pairs:
DataSource => dbi:mysql:session
UserName => www
Password => secret word
b)what is $ENV{EMBPERL_COOKIE_NAME} and why can it be defaulted as
'EMBPERL_UID'

Again from included documentation:

EMBPERL_COOKIE_NAME

(only 1.2b4 or above) Set the name that Embperl uses when it sends the
cookie with the session id. Default is EMBPERL_UID.

Bottom line is I couldn't find a book on embperl. If you can suggest a
book I'll be grateful.

You could start with the included documentation (also available at
http://perl.apache.org/embperl/pod/doc/doc13/HTML/Embperl.htm ), along with
the introductory material at http://perl.apache.org/embperl/pod/intro/ .
 
S

soup_or_power

Juha said:
(e-mail address removed) said:
So, the above gets whatever is stored into the environment variable named
EMBPERL_SESSION_ARGS, and places them into a hash (and returns the hash).
With the above example, the hash would contain name-value pairs:
DataSource => dbi:mysql:session
UserName => www
Password => secret word


Again from included documentation:

EMBPERL_COOKIE_NAME

(only 1.2b4 or above) Set the name that Embperl uses when it sends the
cookie with the session id. Default is EMBPERL_UID.



You could start with the included documentation (also available at
http://perl.apache.org/embperl/pod/doc/doc13/HTML/Embperl.htm ), along with
the introductory material at
http://perl.apache.org/embperl/pod/intro/ .
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)

Many thanks for your clarification

Just curious, where are the session info fdat, udat, and mdat stored?
The code also resets the udat and fdat hashes. For instance:
"$fdat{"f|frequency"}="monthly". I thought the form data in fdat can't
be altered. While at it, what does the pipe (|) symbol mean?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top