Thread Allgemeine Frage zu Modulen (4 answers)
Opened by Gast at 2007-08-01 12:02

Gast Gast
 2007-08-01 12:02
#91594 #91594
Hallo Perl-Gemeinde ;)

versuche mich gerade an Perl zu gewöhnen. Und benötige da, glaube ich, etwas proffisionelle Hilfe.

Habe volgende Konstellation (vereinfacht dargestellt):

Code (perl): (dl )
1
2
3
4
5
6
7
8
#!/usr/bin/perl

use strict;
use warnings;

use module::Main;

die print "Programmfehler!" unless Main::Run();


module/Main.pm
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
package Main;

use strict;
use warnings;

use module::Config;

our $Config = new Config;

sub Run
{
        return -1 unless $Config->Start();
        return 1;
}


module/Config.pm
Code (perl): (dl )
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
package Config;

use strict;
use warnings;

use Tk;
use module::Navi;

sub new
{
        my ($this) = @_;
        bless my $self = {} => (ref $this) || $this;
        
        $self->{mw} = new MainWindow;
        my $fr1 = $self->{mw}->Frame->pack;
        
        return undef unless
                $self->{Navi} = new Navi($fr1);
        
        $self->{Navi}->SetCallBackEvent(\&ViewEvent);
}

sub Start
{
        MainLoop();
}

sub ViewEvent
{
        my($this) = @_; # !!! $this - Kein Objekt. Hä ???
}


module/Navi.pm
Code (perl): (dl )
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
package Navi;

use strict;
use warnings;

use Tk::Tree;

my $EventHandler = undef;

sub new
{
        my($this, $top) = @_;
        
        bless my $self = {} => (ref $this) || $this;
        $self->{tree} = $top->Scrolled
        (
                qw/Tree/
        )
                ->pack;
        
        $self->{tree}->bind('<ButtonPress-1>', [ \&TreeEvent ]);
        $self->{tree}->bind('<KeyPress>'     , [ \&TreeEvent ]);

        #
        # Hier Tree befüllen
        #
        $self->{tree}->autosetmode;
}

sub TreeEvent
{
        my($this) = @_; # !!! Nicht Objekt, sondern Tree=HASH(...) ???
        
        return unless my $sl = $this->info('selection');
    
        &$EventHandler($this->info('data', $sl));
}

sub SetCallBackEvent
{
        my($this, $event) = @_; # Hier $this - o.k.
        $EventHandler = $event;
}


Was mache ich falsch? Warum erhalte ich nicht die Objekt-Referenzen in den Subs?

Bitte um Aufklärung *help*

Vielen Dank!
Alex

View full thread Allgemeine Frage zu Modulen