Mic
view release on metacpan or search on metacpan
lib/Mic/Contracts.pm view on Meta::CPAN
package Mic::Contracts;
use strict;
use Mic::ContractConfig;
sub import {
my (undef, %contract_for) = @_;
Mic::ContractConfig::configure(\ %contract_for);
strict->import();
}
1;
__END__
=head1 NAME
Mic::Contracts
=head1 SYNOPSIS
# example.pl
use Mic::Contracts
'Foo' => { all => 1 }, # all contracts are run
'Bar' => { post => 1 }, # postconditions (and preconditions) are run
'Baz' => { pre => 0 }; # all contracts are skipped
use Foo;
use Bar;
use Baz;
# do stuff with Foo, Bar and Baz
=head1 DESCRIPTION
Allows contracts to be enabled for a given class or interface.
=head1 An Example
The following example illustrates the use of contracts, which are assertions that constrain the visible behaviour of objects.
package Example::Contracts::BoundedQueue;
use Mic::Class
interface => {
class => {
new => {
require => {
positive_int_size => sub {
my (undef, $arg) = @_;
$arg->{max_size} =~ /^\d+$/ && $arg->{max_size} > 0;
},
},
ensure => {
zero_sized => sub {
my ($obj) = @_;
$obj->size == 0;
},
}
},
},
object => {
head => {},
tail => {},
size => {},
max_size => {},
push => {
( run in 4.603 seconds using v1.01-cache-2.11-cpan-364913b4093 )