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.
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |