Toby Inkster > MooseX-DeclareX-Keyword-interface-0.003 > MooseX::DeclareX::Keyword::interface

Download:
MooseX-DeclareX-Keyword-interface-0.003.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 0.003   Source   Latest Release: MooseX-DeclareX-Keyword-interface-0.004

NAME ^

MooseX::DeclareX::Keyword::interface - shiny syntax for MooseX::Interface

SYNOPSIS ^

  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 );

DESCRIPTION ^

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.

BUGS ^

Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=MooseX-DeclareX-Keyword-interface.

SEE ALSO ^

MooseX::DeclareX, MooseX::Interface.

AUTHOR ^

Toby Inkster <tobyink@cpan.org>.

COPYRIGHT AND LICENCE ^

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.

DISCLAIMER OF WARRANTIES ^

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.

syntax highlighting: