in reply to Pure Virtual Functions
and then a class that implements the abstract method:package Foo; use Moose::Role; requires 'table_name'; has 'name' => (is => 'rw'); 1;
and one that should but doesn't:package Abc; use Moose; with 'Foo'; sub table_name { 'ABC_TABLE' } 1;
Then a script to test Abc:package NoTableName; use Moose; with 'Foo'; 1;
(running it)use strict; use warnings; use Abc; my $obj = Abc->new(name => 'Steve'); printf "My name is %s\n", $obj->name;
and one to test NoTableNameC:\Users\arun>perl abc.t My name is Steve
(just compiling it)use strict; use warnings; use NoTableName; my $obj = NoTableName->new(name => 'Bob'); printf "My name is %s\n", $obj->name;
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.
|
|---|