| Class-Data-Annotated documentation | Contained in the Class-Data-Annotated distribution. |
Class::Data::Annotated - Data::Annotated wrapped objects
use Class::Data::Annotated;
my $$obj = Class::Data::Annotated->new();
instantiate an Annotated Data Structure
annotate a peice of the data. if that piece does not exist it will return undef. Otherwise it returns the data annotated.
Returns a Data::Annotated object holding the dictionary of annotations for this object
retrieves the data for this path in the object. returns undef if data location does not exist
returns the annotations for the location in the data specified by the path.
Returns a Data::Path object holding the data in this object
validates a Data::Path path.
| Class-Data-Annotated documentation | Contained in the Class-Data-Annotated distribution. |
package Class::Data::Annotated; use Data::Annotated; use Data::Path; use Carp; use strict; use warnings;
our $VERSION = '0.2'; my $callbacks = { key_does_not_exist => sub {}, index_does_not_exist => sub {}, retrieve_index_from_non_array => sub {}, retrieve_key_from_non_hash => sub {}, };
sub new { my ($class, $struct) = @_; croak('I just gotta have data') unless $struct; return bless {Annotations => Data::Annotated->new(), Data => Data::Path->new($struct, $callbacks)}, $class; }
sub annotate { my ($self, $path, $annotation) = @_; $self->_validate_path($path); if ($self->data()->get($path)) { $self->{Annotations}->annotate($path, $annotation); return $self->data()->get($path); } else { return } }
sub annotations { return shift->{Annotations}; }
sub get { my ($self, $path) = @_; $self->_validate_path($path); return $self->data()->get($path); }
sub get_annotation { my ($self, $path) = @_; $self->_validate_path($path); return $self->annotations->{$path}; }
sub data { return shift->{Data}; }
sub _validate_path { my ($self, $path) = @_; croak('Invalid Path: '.$path) unless $self->annotations()->_validate_path($path); } 1;