[BEGINNER] Embperl question

Discussion in 'Perl Misc' started by soup_or_power@yahoo.com, Apr 6, 2005.

  1. Guest

    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;
    }
    }
     
    , Apr 6, 2005
    #1
    1. Advertising

  2. 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.
     
    Brian McCauley, Apr 6, 2005
    #2
    1. Advertising

  3. Guest

    Re: Embperl question

    Brian McCauley wrote:
    > 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
     
    , Apr 6, 2005
    #3
  4. Juha Laiho Guest

    Re: Embperl question

    said:
    >
    >Brian McCauley wrote:
    >> 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/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)
     
    Juha Laiho, Apr 7, 2005
    #4
  5. Guest

    Re: Embperl question

    Juha Laiho wrote:
    > 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/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?
     
    , Apr 7, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Embperl question

    , Nov 29, 2004, in forum: Perl
    Replies:
    2
    Views:
    471
  2. http_headers_out embperl

    , May 2, 2005, in forum: Perl Misc
    Replies:
    0
    Views:
    119
  3. webgirl
    Replies:
    1
    Views:
    97
    Christopher Nehren
    Jun 24, 2005
  4. Embperl Execute

    , Aug 30, 2005, in forum: Perl Misc
    Replies:
    0
    Views:
    106
  5. Hobo Salesman

    Embperl and mod_perl support

    Hobo Salesman, Jun 20, 2006, in forum: Perl Misc
    Replies:
    1
    Views:
    124
    Mirco Wahab
    Jun 20, 2006
Loading...

Share This Page