Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > [BEGINNER] Embperl question

Reply
Thread Tools

[BEGINNER] Embperl question

 
 
soup_or_power@yahoo.com
Guest
Posts: n/a
 
      04-06-2005
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;
}
}

 
Reply With Quote
 
 
 
 
Brian McCauley
Guest
Posts: n/a
 
      04-06-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> 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.

 
Reply With Quote
 
 
 
 
soup_or_power@yahoo.com
Guest
Posts: n/a
 
      04-06-2005

Brian McCauley wrote:
> (E-Mail Removed) wrote:
>
> > 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.


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

 
Reply With Quote
 
Juha Laiho
Guest
Posts: n/a
 
      04-07-2005
(E-Mail Removed) said:
>
>Brian McCauley wrote:
>> (E-Mail Removed) wrote:
>>
>> > 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.

>
>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/d...ML/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)
 
Reply With Quote
 
soup_or_power@yahoo.com
Guest
Posts: n/a
 
      04-07-2005

Juha Laiho wrote:
> (E-Mail 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
>
> >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/d...ML/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?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Embperl and mod_perl support Hobo Salesman Perl Misc 1 06-20-2006 10:22 AM
Embperl Execute soup_or_power@yahoo.com Perl Misc 0 08-30-2005 08:37 PM
Sharing variables between embPerl and Perl webgirl Perl Misc 1 06-24-2005 07:36 PM
http_headers_out embperl soup_or_power@yahoo.com Perl Misc 0 05-02-2005 04:03 PM
Embperl question dogdog@noemail.com Perl 2 12-01-2004 12:53 AM



Advertisments