|< 1 2 >| | 14 Einträge, 2 Seiten |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
package MyModul; use strict; sub new { my $class = shift; my $self = {}; bless($self, $class); #$self->init(@_) # Startparameter nach $self einlesen return $self; } sub search { my $self = shift; my $name = shift; my $names = {}; $names->{_NAME_} = $name; bless($names); } sub get { my $names = shift; # ich hätte hier gerne noch $self aus new() print $names->{_NAME_}; } 1;
1 2 3 4 5 6 7 8 9 10
use strict; use MyModul; my $objekt = MyModul->new; my $name1 = $objekt->search('Thomas'); my $name2 = $objekt->search('Martin'); print $name1->get,"\n"; #Thomas print $name2->get,"\n"; #Martin
renee+2007-12-09 13:21:54--Der erste Parameter beim Aufruf "$self->..." ist immer $self!
1 2 3 4
sub get { my $self = shift; #allgemeine Daten my $names = shift; #Daten, die nur für das Objekt gültig sind das in search() erzeugt wird }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
#!/usr/bin/perl use strict; use warnings; ####################################################### package MyModul; sub new { my $class = shift; my $self = {}; bless($self, $class); return $self; } sub search { my $self = shift; my $name = shift; return MyModul::Search->new($name); } 1; ####################################################### package MyModul::Search; use base 'MyModul'; sub new { my $class = shift; my $name = shift; my $self = {'_NAME_'=>$name}; bless($self, $class); return $self; } sub get { my $self=shift; return $self->{'_NAME_'}; } 1; ####################################################### package main; my $test=MyModul->new(); my $name_a=$test->search('NAME1'); print $name_a->get()."\n";
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
package Friender::EasyDB; use strict; use DBI; use Friender::Search::Search; sub new { my $class = shift; my $self = {}; bless($self, $class); $self->init(@_); return $self; } sub init { my $self = shift; my $dbh = DBI->connect_cached(@_, { AutoCommit => 0, RaiseError => 1 } ) or die $DBI::errstr; $self->{_DATA_}->{DBH} = $dbh; } sub search { my $self = shift; my $dbh = $self->{_DATA_}->{DBH}; my ($st, @bind) = @_; return Friender::Search::Search->new($dbh, $st, @bind); } sub quick { my $self = shift; my $dbh = $self->{_DATA_}->{DBH}; my ($st, @bind) = @_; return $dbh->selectrow_array($st, undef, @bind); } sub do { my $self = shift; my $dbh = $self->{_DATA_}->{DBH}; my ($st, @bind) = @_; $dbh->do($st, undef, @bind); } sub disconnect { my $self = shift; my $dbh = $self->{_DATA_}->{DBH}; $dbh->disconnect; } 1;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
package Friender::Search::Search; use strict; use SQL::Abstract; sub new { my $class = shift; my $self = {}; bless($self, $class); $self->init(@_); return $self; } sub init { my $self = shift; my ($dbh, $st, @bind) = @_; my $sth = $dbh->prepare($st); $sth->execute(@bind) or die $DBI::errstr; $self->{_DATA_}->{RESULTS} = $sth; } sub get { my $self = shift; my $sth = $self->{_DATA_}->{RESULTS}; return $sth->fetchrow_hashref; } 1;
|< 1 2 >| | 14 Einträge, 2 Seiten |