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

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/ 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/ 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/ 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 line 94 Moose::Util::apply_all_roles('Moose::Meta::Class=HASH(0x368b944)', + 'Foo') called at C:/Perl/site/lib/ line 77 Moose::with('NoTableName', 'Foo') called at C:/Perl/site/lib/Moose +/ line 201 Moose::with('Foo') called at line 5 require called at notablename.t line 3 main::BEGIN() called at line 0 eval {...} called at line 0 Compilation failed in require at notablename.t line 3. BEGIN failed--compilation aborted at notablename.t line 3.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://742160]
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
Find Nodes?
    Voting Booth?
    The most amusing oxymoron is:

    Results (32 votes). Check out past polls.