Sub::Contract::Pool - A pool of all subroutine contracts
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::.*");
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.
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.
$fully_qualified_name
$pool->find_contract($fully_qualified_name)
Return the contract of the subroutine identified by $fully_qualified_name or undef if this subroutine does not exist or has no contract. Example:
undef
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:
/^$regexp$/
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 'Sub::Contract'.
$Id: Pool.pm,v 1.15 2009/06/16 12:23:58 erwan_lemonnier Exp $
Erwan Lemonnier <erwan@cpan.org>
<erwan@cpan.org>
See Sub::Contract.
To install Sub::Contract, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Sub::Contract
CPAN shell
perl -MCPAN -e shell install Sub::Contract
For more information on module installation, please visit the detailed CPAN module installation guide.