| 1 | 1 | ▶ | use 5.008; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 2 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | package Class::Value::SemanticAdapter; | ||
| 6 | our $VERSION = '1.100841'; | ||
| 7 | # ABSTRACT: Adapter for Data::Semantic objects | ||
| 8 | 1 | ▶ | use UNIVERSAL::require; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 1 | ▶ | use parent qw(Class::Value); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | # Default; subclasses can redefine this. But it makes sense to keep the | ||
| 12 | # Data::Domain::* and Data::Semantic::* namespaces in sync. | ||
| 13 | sub semantic_class_name { | ||
| 14 | my $self = shift; | ||
| 15 | (my $semantic_class_name = ref $self) =~ | ||
| 16 | s/^Class::Value::/Data::Semantic::/; | ||
| 17 | $semantic_class_name; | ||
| 18 | } | ||
| 19 | |||
| 20 | # FIXME might cache the adaptee unless $self->dirty; | ||
| 21 | sub adaptee { | ||
| 22 | my $self = shift; | ||
| 23 | my $semantic_class_name = $self->semantic_class_name; | ||
| 24 | $semantic_class_name->require; | ||
| 25 | $semantic_class_name->new($self->semantic_args); | ||
| 26 | } | ||
| 27 | |||
| 28 | # Return those of the value object's attributes that are relevant to the | ||
| 29 | # semantic data object constructor. | ||
| 30 | sub semantic_args { () } | ||
| 31 | |||
| 32 | sub is_valid_value { | ||
| 33 | my ($self, $value) = @_; | ||
| 34 | $self->adaptee->is_valid($value); | ||
| 35 | } | ||
| 36 | |||
| 37 | sub normalize_value { | ||
| 38 | my ($self, $value) = @_; | ||
| 39 | $self->adaptee->normalize($value); | ||
| 40 | } | ||
| 41 | |||
| 42 | sub is_valid_normalized_value { | ||
| 43 | my ($self, $normalized) = @_; | ||
| 44 | $self->adaptee->is_valid_normalized_value($normalized); | ||
| 45 | } | ||
| 46 | 1; | ||
| 47 | |||
| 48 | |||
| 49 | __END__ | ||