1 2 3 4 5 6 7 8 9 10 11 12
sub new { @_ == 2 || die 'Usage: class->new($db)'; my ($class_session, $db) = @_; my $self = bless { db => $db, sessionLang => 'en', sessionID => '', sessionLiveTime => 900, }, $class_session; return $self; }
1 2 3 4 5 6
sub getUsername { my $self = shift; $sth = $self->{db}->prepare($sql) || die "cannot prepare query, errmsg = $DBI::errstr"; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
use session; my $dbh = DBI->connect($dsn, $user, $password) || die "can't connect, errmsg = $DBI::errstr"; my $session = session->new($dbh); if($session->session()){ # Session aktiv # Hier werden nun weitere Routinen der Klasse aufgerufen print $session->getUsername; # Das Problem print $session->getField("parameterA","parameterB"); }else{ # Session nicht aktiv }
1 2 3 4 5 6 7 8 9 10
sub getField{ my $self = shift; my $usernamestring = $_[1]; my $type = $_[0]; $sth = $self->{db}->prepare($sql) || die "cannot prepare query, errmsg = $DBI::errstr"; }
1 2 3 4 5 6 7
package a; sub new{return bless {db=>"db"}, shift} sub foo{my $self=shift;say "db=$self->{db}\nParameter:@_"}; package main; my $x=a->new(); $x->foo("x", "y");