Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6804887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:31:15+00:00 2026-05-26T19:31:15+00:00

I have a perl script that uses the CGI::Session::Drive::memcached, but I want to be

  • 0

I have a perl script that uses the CGI::Session::Drive::memcached, but I want to be able to fallback on the default Session driver or another driver if it’s available on the system…

This is how I started off using Memcache, but this doesnt necessarily solve the problem of the case when Cache::Memecached and/or CGI::Session::Driver::memcached are not available…

package MySession;

use Moose::Role;
use Moose::Util::TypeConstraints; 
use namespace::autoclean;

use CGI::Session ('-ip_match');
use CGI::Session::Driver::memcached;
use Cache::Memcached::Fast;

#would be nice to create this conditionally, or use a delegate maybe
has 'memeCached' => (
 is        => 'rw', 
 isa       => 'Maybe[Cache::Memcached::Fast]', 
 default => sub{ return Cache::Memcached::Fast->new( {'servers' => [ '10.x.x.x.:10001' ],'compress_threshold' => '100000','nowait' => 1,'utf8' => 1} ) },

);


  sub buildSession{
    my($this,$cgi,$sessionDir) = @_;

    $cgi = $cgi || $this->getCGI();

    my $sid = $this->SID();        
    my $mem = $this->memeCached(); 

    my $sss;

    if(!$mem){
        $sss = CGI::Session->load(undef, $cgi, {Directory=>$sessionDir}) or die CGI::Session->errstr();
    }else{
            $sss = CGI::Session->load( "driver:memcached", $cgi, { Memcached => $mem }) or die CGI::Session->errstr();
    }

...

Then this got me thinking, how do I do this — in a general sense? or what’s the best way to do this (especially using Moose)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:31:16+00:00Added an answer on May 26, 2026 at 7:31 pm

    I had a similar situation. We use Windows domains, which I can connect to Net::LDAP. In my program, I want to be able to take the user ID jsmith, and instead of printing on the user ID, I want to be able to print out the name John Smith.

    Many people at my company use my program, but not all are Perl experts and most wouldn’t know how to install a Perl module. And, since Net::LDAP is not a standard module, many people don’t have it.

    Instead, I wanted a fallback routine. If I could look up the name with Net::LDAP, I would print the name, if I couldn’t load Net::LDAP, I would fallback and just print the user ID.

    I used the following for testing if Net::LDAP was installed, and load it if possible:

    BEGIN {
        eval { require Net::LDAP; };
        our $Net_Ldap_Status  = 1 if (not $@);
    }
    

    What you have to understand is that:

    use Foo::Bar;
    

    is the same as:

    BEGIN {
        require Foo::Bar;
    }
    

    It loads in the module at compile time. By surrounding the require with an eval I can test whether the statement succeeds (and the module is loaded) or fails (the module doesn’t load, but the program doesn’t crash either.) I can then check $@ to see if the module loaded or not. $@ is the error message that eval sets. If $@ is null, then the module exists and was loaded successfully.

    I need to use a package variable (the our $Net_Ldap_Status instead of my $Net_Ldap_Status) or the variable will be lost when the program runs. (I’m not even sure if my $Net_Ldap_Status would work in a BEGIN statement).

    Now, here’s where things get funky…

    When I need to check $Net_Ldap_Status, I need to redeclare it:

    our $Net_Ldap_Status;
    

    or I tend to get that non-declared variable error. The funny thing is that it doesn’t lose its previous value by redeclaring it. Thus, somewhere in my code is:

    our $Net_Ldap_Status;
    if ($Net_Ldap_Status) {
       print "Code if Net::LDAP is loaded.\n";
    }
    else {
       print "Fallback Code if no Net::LDAP\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Perl script that uses WWW::Mechanize to read from a file and
I have a perl cgi script that's fairly resource intensive (takes about 2 seconds
I currently have a Perl CGI script that parses incoming XML requests using XML::Simple
I have a Perl script that uses Term::ANSIColor . It used to be the
I have a Perl script that works on Windows XP. It uses File::Copy's move
I have a Perl script that uses Selenium to fetch a HTML document called
I have a simple perl script that uses DBD::Oracle to run a query and
I have a Perl script that uses LWP::UserAgent to download a webpage which it
I have an existing Perl script that uses the FTP object to send a
I have a Perl script that processes a bunch of file names, and uses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.