Now, I wanna be able of doing:Object - class toString() - method File - class, inherits Object open(:$file) - metod ( $file paramerer optional as it could have + been send using File's constructor) close() - method Stat - Inherits File getSize() - method getModTime() - method
Now, as you can see here I can do getSize() since the Stat object is supposed to be loaded in there aswell! With inheritance is quite easy. But how to solve this? Its supposed to go recursive down from where you create something. In this case from Object::File as everything below there is supposed to be the File objects functionality! (Object::File::*::*...)use Object::File; my $file = File->new("bah.mp3"); my $size = $file->getSize();
and voilá. You know see what you can do with the file!!! (Should I patent this? ;) )use Object::File; use Data::Dumper; my $file = File->new("bah.mp3"); print Dumper($file->find_methods());
But this doesn't really add the functionality to the File as shown dumping out the data with the find_methods(); sub mentioned in the other thread. Well, atleast there is no reference to the methods within the object...package Object; use strict; use warnings; use lib "."; sub new { my ($class) = @_; my $self = { _objectname => $class, }; my @sub_modules = glob("./Object/" . $class . "/*.pm"); # Load sub modules for the class foreach (@sub_modules) { #print $_ . "\n"; my ($pluginName) = $_ =~ /(\w+).pm/; #print "Class: " . $class . "\n"; require "./Object/$class/$pluginName.pm"; } bless $self, $class; return $self; } sub toString { my $self = shift; return $self->{'_objectname'}; }
In reply to Loading Functionality From SubModules by Ace128
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |