[MTOS-dev] scorabe MT::Category
Hirotaka Ogawa
hirotaka.ogawa at gmail.com
Thu May 8 20:11:57 PDT 2008
Tim,
Basically, I love your idea that allows users to define any XXX-able
interfaces as well as adopt any pre-existed or user-defined classes to
them.
Can you please acknowledge my understanding.
Assuming that we have a set of classes using multiple inheritance as follows:
#------------------------
# Scorable.pm
package Scorable;
use strict;
sub score {
my $self = shift;
print $self->name . " is scored.\n";
}
1;
#------------------------
# Taggable.pm
package Taggable;
use strict;
sub tag {
my $self = shift;
print $self->name . " is tagged.\n";
}
1;
#------------------------
# Object.pm
package Object;
use strict;
use base qw(Taggable Scorable);
sub new {
my($class, $name) = @_;
bless { name => $name }, $class;
}
sub name {
my $self = shift;
$self->{name};
}
1;
#------------------------
These can be rewrite by using Exporter module as like:
#------------------------
# Scorable.pm
package Scorable;
use strict;
use base qw(Exporter);
our @EXPORT = qw(score);
sub score {
my $self = shift;
print $self->name . " is scored.\n";
}
1;
#------------------------
# Taggable.pm
package Taggable;
use strict;
use base qw(Exporter);
our @EXPORT = qw(tag);
sub tag {
my $self = shift;
print $self->name . " is tagged.\n";
}
1;
#------------------------
# Object.pm
package Object;
use strict;
use Taggable;
use Scorable;
sub new {
my($class, $name) = @_;
bless { name => $name }, $class;
}
sub name {
my $self = shift;
$self->{name};
}
1;
#------------------------
So, in order to define another XXX-able interface and then adopt
Object to it, we just need an "Object"-class method to import another
mixin.
Is that right?
On Fri, May 9, 2008 at 4:36 AM, Timothy Appnel <tim at appnel.com> wrote:
> On Thu, May 8, 2008 at 2:44 PM, Jay Allen <jay at endevver.com> wrote:
>
>> 1) Isn't Sub::Install a massive hack or am I misremembering some
>> discussion about another module with similar functionality?
>
> Hack? I guess any time of dynamicmethod loading or creation is a hack.
> Massive? I wouldn't say so. I takes a common hack much cleaner.
>
> "This module makes it easy to install subroutines into packages
> without the unslightly mess of no strict or typeglobs lying about
> where just anyone can see them."
>
> What clean(er) alternate to you have in mind? Something in AUTOLOAD or
> a method like mk_accessor (see Class::Accessor) which essentially does
> what Sub::Install does, but with specific code. In memory serves, this
> is also isn't much different from what handler_to_coderef does either.
>
> The only other idea I have is a conditional require and import that
> happens when a MT::Object class is being loaded. this would assume
> that the taggable and scorable mixins are exporting all necessary
> methods. Something like...
>
> if MT->taggable($model) {
> require MT::Taggable;
> import MT::Taggable qw(:all);
> }
>
> That might work.
>
>> 2) Is there a preferred OO method of achieving dynamic multiple
>> inheritance in Perl (where it CAN but need not (for everyone) inherit
>> from other classes) without using Sub::Install?
>
> Not sure what you are asking here. Do you mean appending a class name
> to the ISA array that contains the list of superclasses? I suppose
> you could but that sounds even more dangerous then my proposal.
>
> <tim/>
>
> --
> Timothy Appnel
> Appnel Solutions
> http://appnel.com/
> _______________________________________________
> MTOS-dev mailing list
> MTOS-dev at sixapart.com
> http://www.sixapart.com/mailman/listinfo/mtos-dev
>
--
Hirotaka Ogawa
http://twitter.com/ogawa
http://as-is.net/blog/
More information about the MTOS-dev
mailing list