| 1 | package Coat::Persistent::Constraint; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | # Singleton for storing constraints | ||
| 7 | my $REGISTRY = {}; | ||
| 8 | |||
| 9 | sub add_constraint { | ||
| 10 | my ($class, $constraint, $caller, $attribute, $value) = @_; | ||
| 11 | $REGISTRY->{$constraint}{$caller}{$attribute} = $value; | ||
| 12 | } | ||
| 13 | |||
| 14 | sub get_constraint { | ||
| 15 | my ($class, $constraint, $caller, $attribute) = @_; | ||
| 16 | $REGISTRY->{$constraint}{$caller}{$attribute} || 0; | ||
| 17 | } | ||
| 18 | |||
| 19 | sub remove_constraint { | ||
| 20 | my ($class, $constraint, $caller, $attribute) = @_; | ||
| 21 | delete $REGISTRY->{$constraint}{$caller}{$attribute}; | ||
| 22 | } | ||
| 23 | |||
| 24 | sub list_constraints { | ||
| 25 | my ($class, $constraint, $caller) = @_; | ||
| 26 | keys %{ $REGISTRY->{$constraint}{$caller} }; | ||
| 27 | } | ||
| 28 | |||
| 29 | 1; |