Class::Value::SemanticAdapter - Adapter for Data::Semantic objects


Class-Value-SemanticAdapter documentation Contained in the Class-Value-SemanticAdapter distribution.

Index


Code Index:

NAME

Top

Class::Value::SemanticAdapter - Adapter for Data::Semantic objects

VERSION

Top

version 1.100841

DESCRIPTION

Top

This class is an adapter, a wrapper, that turns Data::Semantic objects into Class::Value objects.

METHODS

Top

semantic_class_name

Returns the corresponding semantic class name. This method provides a default mapping, the idea of which is to mirror the layout of the Data::Semantic class tree. If you have a different mapping, override this method in a subclass.

So in the Class::Value::URI::http class, it will return Data::Semantic::URI::http.

adaptee

Takes the results of semantic_class_name() and semantic_args(), loads the semantic data class and returns a semantic data object with the given args passed to its constructor.

semantic_args

Return those of the value object's attributes, in hash format, that are relevant to the semantic data object constructor.

is_valid_value

Like the same method in Class::Value, but forwards the question to the adapted data semantic object.

normalize_value

Like the same method in Class::Value, but forwards the question to the adapted data semantic object.

is_valid_normalized_value

Like the same method in Class::Value, but forwards the question to the adapted data semantic object.

INSTALLATION

Top

See perlmodinstall for information and options on installing Perl modules.

BUGS AND LIMITATIONS

Top

No bugs have been reported.

Please report any bugs or feature requests through the web interface at http://rt.cpan.org/Public/Dist/Display.html?Name=Class-Value-SemanticAdapter.

AVAILABILITY

Top

The latest version of this module is available from the Comprehensive Perl Archive Network (CPAN). Visit http://www.perl.com/CPAN/ to find a CPAN site near you, or see http://search.cpan.org/dist/Class-Value-SemanticAdapter/.

The development version lives at http://github.com/hanekomu/Class-Value-SemanticAdapter/. Instead of sending patches, please fork this project using the standard git and github infrastructure.

AUTHOR

Top

  Marcel Gruenauer <marcel@cpan.org>

COPYRIGHT AND LICENSE

Top


Class-Value-SemanticAdapter documentation Contained in the Class-Value-SemanticAdapter distribution.

use 5.008;
use strict;
use warnings;

package Class::Value::SemanticAdapter;
our $VERSION = '1.100841';
# ABSTRACT: Adapter for Data::Semantic objects
use UNIVERSAL::require;
use parent qw(Class::Value);

# Default; subclasses can redefine this. But it makes sense to keep the
# Data::Domain::* and Data::Semantic::* namespaces in sync.
sub semantic_class_name {
    my $self = shift;
    (my $semantic_class_name = ref $self) =~
      s/^Class::Value::/Data::Semantic::/;
    $semantic_class_name;
}

# FIXME might cache the adaptee unless $self->dirty;
sub adaptee {
    my $self                = shift;
    my $semantic_class_name = $self->semantic_class_name;
    $semantic_class_name->require;
    $semantic_class_name->new($self->semantic_args);
}

# Return those of the value object's attributes that are relevant to the
# semantic data object constructor.
sub semantic_args { () }

sub is_valid_value {
    my ($self, $value) = @_;
    $self->adaptee->is_valid($value);
}

sub normalize_value {
    my ($self, $value) = @_;
    $self->adaptee->normalize($value);
}

sub is_valid_normalized_value {
    my ($self, $normalized) = @_;
    $self->adaptee->is_valid_normalized_value($normalized);
}
1;


__END__