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
package main;
use strict;
use CGI qw/:standard/;
use CGI::Carp 'fatalsToBrowser';
use Date::Calc qw(:all);
use Storable qw(nfreeze thaw);
use DBI;
use DBD::Pg qw(:pg_types);
use utf8;
use Encode qw(encode decode from_to);
use Encode::Encoder qw(encoder);
use lib "/wwws/cgi-bin/praktver"; # Location B
use PGtest;
...
$Modul=PraxisModul->new();
...
package PraxisModul;
use CGI;
use Seitenmodul;
our @ISA = qw( Seitenmodul );
...
sub new {
my $class=shift;
my $self={};
bless($self, $class);
$self->SUPER::init(); # <-- Fehlerzeile 163
$self->init();
return $self;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package Seitenmodul;
use strict;
use PGtest;
use DBI;
use CGI qw/:standard/;
use CGI::Carp 'fatalsToBrowser';
sub new {
my $class=shift;
my $self={};
bless($self, $class);
$self->init();
return $self
}
sub init {
my $self=shift;
# Finde heraus um welchen Modulaufruf es sich handelt
my @N=split(/\//,shift);
$MODUL =$N[@N-2];
...
}
Can't locate object method "init" via package "PraxisModul" at /wwws/cgi-bin/praktver/indextest.pl line 163.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
package Seitenmodul; sub new{ return bless{},shift; } sub init{print 123} ########################################################################### package PraxisModul; @ISA = qw( Seitenmodul ); sub new { my $class = shift; my $self = $class->SUPER::new;; $self->init; return $self; } ########################################################################### package main; $Modul = PraxisModul->new();
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
#!/usr/bin/perl use strict; use warnings; use utf8; my $Modul=PraxisModul->new(); $Modul->echo(); {package PraxisModul; use base 'Seitenmodul'; use strict; use warnings; sub new { my $class=shift; my $self=$class->SUPER::new(); return $self; } sub echo { my $self=shift; print "Echo "; $self->SUPER::echo(); } 1;}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
package Seitenmodul; use strict; use warnings; sub new { my $class=shift; my $self={}; bless($self, $class); $self->init(); return $self; } sub init { my $self=shift; } sub echo { print "BLA\n"; } 1;
Guest DavidDer Author der parent.pm hat base.pm schon um einiges runtergemacht. Sicher wohl auch um sein eigenes Modul besser durchzukriegen.
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
use strict; use warnings; use Data::Dumper; package main; tie my %h, 'UcHash'; $h{foo} = 1; print Dumper \%h; # Eine kleine eigene Klasse stellt Großbuchstaben # in den Schlüsseln sicher package UcHash; use strict; use warnings; use Tie::Hash; use base 'Tie::StdHash'; #our @ISA = qw(Tie::StdHash); # Bei der Wertzuweisung werden alle Keys in Großbuchstaben umgewandelt # STORE wird bei jeder Wertzuweisung aufgerufen sub STORE { my ($self, $key, $value ) = @_; $self->{uc $key} = $value; } 1;#########################################################################
2012-06-13T20:03:04 topegDas liegt daran das im Fall our @ISA dieses erst zu Laufzeit gefüllt wird. Genau dann wenn der Interpreter daran vorbei kommt. Steht es zu weit unten ist es noch leer. Das kann man mit einem passenden "BEGIN" korrigieren.
base und auch parent machen das von sich aus.