NAME
Sub::Contract::Pool - A pool of all subroutine contracts
SYNOPSIS
use Sub::Contract::Pool qw(get_contract_pool);
my $pool = get_contract_pool();
# disable all contracts in package My::Test
foreach my $contract ($pool->find_contracts_matching("My::Test::.*")) {
$contract->disable;
}
# or simply
$pool->disable_contracts_matching("My::Test::.*");
DESCRIPTION
Every subroutine contract created with Sub::Contract is automatically added to a common pool of contracts.
Contracts are instances of Sub::Contract.
You can query this pool to retrieve contracts based on the qualified name of the contractors (ie package name + subroutine name). You can then modify, recompile, enable and disable contracts that you fetch from the pool, at any time during runtime.
Sub::Contract::Pool uses a singleton pattern, giving you access to the common contract pool.
API
my $pool = get_contract_pool()
;-
Return the contract pool.
$pool->list_all_contracts
-
Return all contracts registered in the pool.
$pool->has_contract($fully_qualified_name)
-
Return true if the subroutine identified by
$fully_qualified_name
has a contract. $pool->find_contract($fully_qualified_name)
-
Return the contract of the subroutine identified by
$fully_qualified_name
orundef
if this subroutine does not exist or has no contract. Example:my $c = get_contract_pool->find_contract("Foo::Bar::yaph") || die "couldn't find contract"; $c->clear_cache;
$pool->find_contracts_matching($regexp)
-
Find all the contracts registered in the pool and whose contractor's fully qualified names matches the pattern
/^$regexp$/
. Example:foreach my $c (get_contract_pool->find_contract("Foo::Bar::*")) { $c->clear_cache; }
$pool->enable_all_contracts
-
Enable all the contracts registered in the pool.
$pool->disable_all_contracts
-
Disable all the contracts registered in the pool.
$pool->enable_contracts_matching($regexp)
-
Enable all the contracts registered in the pool whose contractor's fully qualified names matches the pattern
/^$regexp$/
. $pool->disable_contracts_matching($regexp)
-
Disable all the contracts registered in the pool whose contractor's fully qualified names matches the pattern
/^$regexp$/
.
SEE ALSO
See 'Sub::Contract'.
VERSION
$Id: Pool.pm,v 1.15 2009/06/16 12:23:58 erwan_lemonnier Exp $
AUTHOR
Erwan Lemonnier <erwan@cpan.org>
LICENSE
See Sub::Contract.