Thread mal wieder design frage (8 answers)
Opened by mark05 at 2011-06-01 08:35

mark05
 2011-06-01 08:35
#149331 #149331
User since
2010-01-05
129 Artikel
BenutzerIn
[default_avatar]
hi

ich habe gestern mal wieder etwas rum gespielt ;)

oberbegriff "tools sammlung".
idee all die geschrieben routinen via vererbung in einm objekt zusammenfassen
aber nur die die am jeweiliges .pm existiert.

ziel 1 objekt das via baukasten prinzip sich erweitern , zusammen stellen
laesst.


beispiel

Code: (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
package Hgltools;
use strict;
use warnings;
use English '-no_match_vars';
use Carp;
use feature qw/switch/;
use Readonly;
use vars qw($VERSION @ISA @EXPORT_OK);

if ( eval 'use Hglreadfile; 1;' ) {push @ISA,'Hglreadfile';};

require Exporter;
use base qw(Exporter);
@EXPORT_OK = qw ();

sub new {
my @opt = @_;
my $shelf = {};
my $class = $opt[0];
my $args = $opt[1];
$class = ref($class) || $class;
bless $shelf, $class;
return $shelf;
} # end sub new

$VERSION = '0.01'
1;


und hglreadfile

Code: (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
package Hglreadfile;
use strict;
use warnings;
use English '-no_match_vars';
use Carp;
use feature qw/switch/;
use Readonly;

require Exporter;
use vars qw($VERSION @ISA @EXPORT_OK);
use base qw(Exporter);
@EXPORT_OK = qw (_readfile);

sub new {
my @opt = @_;
my $shelf = {};
my $class = $opt[0];
my $args = $opt[1];
$class = ref($class) || $class;
bless $shelf, $class;
return $shelf;
} # end sub new

sub _readfile {
my ($shelf,$args) = @_;
my $file = \$args->{'file'};
my @content = ();

if ( not ( -e ${$file} ) ) { return ('filenotexist'); }

open my $FH , '<', ${$file} or croak "can't open ${$file} for _readfile $ERRNO";
while (<$FH>) {
chomp;
push @content,$_;
}
close $FH or croak $ERRNO;
return (@content);
}
1;


somit habe ich _readfile immer im objekt hgltools zuverfuegung wenn
dieses verfuegber ist .

nun stellt sich fuer mich die frage

Code: (dl )
if ( eval 'use Hglreadfile; 1;' ) {push @ISA,'Hglreadfile';};


ist der push nach @ISA erlaubt ? bzw sauberer stil , oder gibt es
einem moeglichkeit das besser(schoener) zu loesen.

holger

View full thread mal wieder design frage