Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Pure Virtual Functions

by Arunbear (Prior)
on Feb 07, 2009 at 19:27 UTC ( #742160=note: print w/replies, xml ) Need Help??


in reply to Pure Virtual Functions

I've started using Moose for implementing abstract classes. Here is a demo, starting with your Foo module:
package Foo; use Moose::Role; requires 'table_name'; has 'name' => (is => 'rw'); 1;
and then a class that implements the abstract method:
package Abc; use Moose; with 'Foo'; sub table_name { 'ABC_TABLE' } 1;
and one that should but doesn't:
package NoTableName; use Moose; with 'Foo'; 1;
Then a script to test Abc:
use strict; use warnings; use Abc; my $obj = Abc->new(name => 'Steve'); printf "My name is %s\n", $obj->name;
(running it)
C:\Users\arun>perl abc.t My name is Steve
and one to test NoTableName
use strict; use warnings; use NoTableName; my $obj = NoTableName->new(name => 'Bob'); printf "My name is %s\n", $obj->name;
(just compiling it)
C:\Users\arun>perl -c notablename.t 'Foo' requires the method 'table_name' to be implemented by 'NoTableNa +me' at C:/Perl/site/lib/Moose/Meta/Role/Application.pm line 59 Moose::Meta::Role::Application::apply('Moose::Meta::Role::Applicat +ion::ToClass=HASH(0x23ea6a4)', 'Moose::Meta::Role=HASH(0x379d674)', ' +Moose::Meta::Class=HASH(0x368b944)') called at C:/Perl/site/lib/Moose +/Meta/Role/Application/ToClass.pm line 18 Moose::Meta::Role::Application::ToClass::apply('Moose::Meta::Role: +:Application::ToClass=HASH(0x23ea6a4)', 'Moose::Meta::Role=HASH(0x379 +d674)', 'Moose::Meta::Class=HASH(0x368b944)') called at C:/Perl/site/ +lib/Moose/Meta/Role.pm line 448 Moose::Meta::Role::apply('Moose::Meta::Role=HASH(0x379d674)', 'Moo +se::Meta::Class=HASH(0x368b944)') called at C:/Perl/site/lib/Moose/Ut +il.pm line 94 Moose::Util::apply_all_roles('Moose::Meta::Class=HASH(0x368b944)', + 'Foo') called at C:/Perl/site/lib/Moose.pm line 77 Moose::with('NoTableName', 'Foo') called at C:/Perl/site/lib/Moose +/Exporter.pm line 201 Moose::with('Foo') called at NoTableName.pm line 5 require NoTableName.pm called at notablename.t line 3 main::BEGIN() called at NoTableName.pm line 0 eval {...} called at NoTableName.pm line 0 Compilation failed in require at notablename.t line 3. BEGIN failed--compilation aborted at notablename.t line 3.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://742160]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2020-04-04 00:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The most amusing oxymoron is:
















    Results (32 votes). Check out past polls.

    Notices?