fmk has asked for the wisdom of the Perl Monks concerning the following question:

hey, I am a novice in perl and trying to write a little login package which i want to integrate into some scripts. Is it stylistic okay / dangerous to open the session inside the package for use with the in-package functions, and simultaneously pass them to the script which uses the package? Or is there a better way to do this? Example:
use CGI::Session; my $s; sub new_session { $s = CGI::Session->new() or croak CGI::Session->errstr(); } sub check_perm { my $req_perm = shift; if ($s->param('_perm') < $req_perm) { print $s->header(), 'sorry, no permussion'; exit(); } }
-- some_script.pl --
use login; my $s = new_session(); check_perm(1); $s->param( _some_param => 'some_value'); my $value = $s->param('_some_param');
Please exuse my poor english, regards

Replies are listed 'Best First'.
Re: Using CGI::Session inside a package?
by almut (Canon) on Jun 14, 2009 at 08:34 UTC

    I don't see any compelling reason not to put it in a package :)  It's no more or less dangerous than having it in the main script; and stylistically it's fine, too (IMHO).

    But better name it Login (1st letter uppercase) — all-lowercase package names are "reserved" for pragmata, like use strict;