1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
package Package::Name; use Some::Module qw(function); sub new { my $class = shift; my $self = { farbe => 'grün', breite => 17, höhe => 13, } return bless $self, $class; } sub my_method { my $self = shift; # ... # ... my $return = function( $self ); # ... }
QuoteYou have the same problem as breaking encapsulation because you have to assume that you know what the internal structure of the reference is. If you are going to do that, you can just ignore the object-oriented stuff and access the structure directly.
2014-03-02T20:34:15 MuffiRoles würden bei mir leider ausscheiden, da Perl sie nicht nativ kann und ich keinem unnötigen Bloat beim use meines Moduls aufzwingen würde.
2014-03-03T16:26:37 KuerbisGibt es dazu Beispiele im Netz, wo so etwas gemacht wird?
2014-03-04T10:05:48 GwenDragonAllen Ernstes, du empfiehlst irgendwelche Tricks weiter, bei denen du nicht weißt ob Kuerbis das versteht und richtig in seine Module einbaut?
2014-03-03T17:02:10 rostiJa, guck mal in Config::IniFiles, da wird die Instanz in eine Subklasse übergeben, das ist ein ziemlich wilder Hack, hab auch ne Weile gebraucht, bis ich das verstanden habe ;)
2014-03-04T19:03:19 rosti
package Config::IniFiles::_section;
Und da passiert Einiges ;)