Thanks for the suggestion. I'll test these modules, a quickly look in the code shows that they use a different approach to declare abstract methods (using import) but the idea is basically the same.

In the other hand Class::Virtually::Abstract will not work with code generator modules and it uses eval, something I prefer not to use.

Updated

Here it goes the test description. First I modified the original code to use Class::Virtual in the Animal class:

package Animal; use base qw(Class::Virtual); use strict; use warnings; sub new { my $class = shift; # hash reference my $self = shift; bless $self, $class; return $self; } __PACKAGE__->virtual_methods(qw(get_sound get_color)); 1;

Then I changed the test.pl script:

use strict; use warnings; use Animal::Dog; use Animal::Duck; my $dog = Animal::Dog->new( { name => 'Atila' } ); my $duck = Animal::Duck->new( { name => 'Donald' } ); print $dog->get_name(), ' says ', $dog->get_sound(), "\n"; my @missing = Animal::Duck->missing_methods(); warn 'Animal::Duck forgot to implement ' . join ', ', @missing if @mis +sing; print $duck->get_name(), ' says ', $duck->get_sound(), "\n";

Finally, the results:

C:\>test.pl Atila says "bark bark!" Animal::Duck forgot to implement get_sound at C:\test.pl line 12. Animal::Duck forgot to implement get_sound() at C:\test.pl line 14

While using the method virtual_methods looks more simple to use than having to type several times sub something :Abstract the module forces you to use more code (using the missing_methods method) just to check if you didn't forgot something.

I think I'll change the Attribute::Abstract to use something like virtual_methods: while using Attribute::Handlers looks fancy, is not really necessary.

Alceu Rodrigues de Freitas Junior
---------------------------------
"You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill

In reply to Re^2: Dealing with abstract methods in Perl 5.8 by glasswalk3r
in thread Dealing with abstract methods in Perl 5.8 by glasswalk3r

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.