MooseX::DeclareX::Keyword::interface - shiny syntax for MooseX::Interface
use MooseX::DeclareX keywords => [qw/ class interface /], plugins => [qw/ guard build test_case /]; interface BankAccountAPI { requires 'deposit'; requires 'withdraw'; requires 'balance'; test_case numeric_balance { Scalar::Util::looks_like_number( $_->balance ) } } class BankAccount with BankAccountAPI { has owner => ( is => 'ro', isa => 'Str', required => 1, ); has balance => ( traits => ['Number'], is => 'rw', isa => 'Num', handles => { deposit => 'add', withdraw => 'sub', }, ); build balance { 0 } guard withdraw ($amt) { confess "insufficient funds" unless $self->balance >= $amt } } interface DDBankAccountAPI extends BankAccountAPI { requires 'setup_direct_debit'; requires 'pay_direct_debit'; } BankAccountAPI->meta->test_implementation( BankAccount->new );
This distribution adds a new keyword and a new plugin to MooseX::DeclareX.
interface
Defines an interface. An interface is much like a role, but with some heavy restrictions - it can't define any methods (just require implementing classes to define them), and it can only extend other interfaces, not roles. See MooseX::Interface for details.
test_case
Sets up test cases for an interface.
Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=MooseX-DeclareX-Keyword-interface.
MooseX::DeclareX, MooseX::Interface.
Toby Inkster <tobyink@cpan.org>.
This software is copyright (c) 2012 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
To install MooseX::DeclareX::Keyword::interface, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::DeclareX::Keyword::interface
CPAN shell
perl -MCPAN -e shell install MooseX::DeclareX::Keyword::interface
For more information on module installation, please visit the detailed CPAN module installation guide.