NAME

MooseX::Interface::Tutorial - random thoughts that might one day become a proper tutorial

EXAMPLES

Describing your object's attributes with interfaces

Here's a good way of using interfaces. Rather than saying that your website's logger must be an instance of a particular class (isa), specify an interface that the object must implement (does).

The object can be tested against the interface at run time.

  package Website
  {
    use Moose;
    
    has logger => (
      is    => 'ro',
      does  => 'Website::LoggerAPI',
    );
    
    sub BUILD {
      my $self = shift;
      Website::LoggerAPI->meta->test_implementation($self->logger)
        or confess "logger does not implement Website::LoggerAPI";
    }
    
    ...;
  }
  
  package Website::LoggerAPI
  {
    use MooseX::Interface;
    requires 'log_message';
    test_case { ... };
  }

BUGS

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

SEE ALSO

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.