Greetings!

This is somewhat a followup on the post I did here: 591709

Now the idea is basicly the following:
I have this structure:
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, I wanna be able of doing:
use Object::File; my $file = File->new("bah.mp3"); my $size = $file->getSize();
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::*::*...)
The thing is that I shouldn't have to know that there is a Stat module really. Since as you can see in the older thread, there is a method to get all methods an object has. So, the idea is that one can just do:
use Object::File; use Data::Dumper; my $file = File->new("bah.mp3"); print Dumper($file->find_methods());
and voilá. You know see what you can do with the file!!! (Should I patent this? ;) )
I have done this so far in the Object (as I assume this is probably the best place to do this since this is ALWAYS run as its the top 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'}; }
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...

Ideas how to solve this?

Thanks,
Ace

In reply to Loading Functionality From SubModules by Ace128

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.