Repository::Simple::Property - Repository properties


Repository-Simple documentation Contained in the Repository-Simple distribution.

Index


Code Index:

NAME

Top

Repository::Simple::Property - Repository properties

SYNOPSIS

Top

See Repository::Simple::Node.

DESCRIPTION

Top

Each instance of this class represents a single property of a node.

To retrieve a property instance, do not construct the object directly. Rather, use the methods associated with a node to retrieve the properties associated with that node:

  my @properties = $node->properties;
  for my $property (@properties) {
      print $property->name, " = ", $property->value->get_scalar;
  }

Each property has a parent (node), a name, a value, and a type. The name is non-empty string identifying the property. The value is a valid value according to the property type. The type is an instance of Repository::Simple::Type::Property. If a property value is set to undef, this is the same as deleting the property from the parent node.

$node = $self->parent

Get the node to which this property belongs.

$name = $self->name

Get the name of the property.

$path = $self->path

Get the full path to the property.

$value = $self->value

Retrieve the value stored in the property.

$type = $self->type

Retrieve the Repository::Simple::Type::Property used to validate and store values for this property.

$property->save

Tells the storage engine to save the property. If you've modified the property somehow, the change might already have been made. However, the change is not guaranteed until this method is called.

AUTHOR

Top

Andrew Sterling Hanenkamp, <hanenkamp@cpan.org>

LICENSE AND COPYRIGHT

Top


Repository-Simple documentation Contained in the Repository-Simple distribution.
package Repository::Simple::Property;

use strict;
use warnings;

our $VERSION = '0.06';

use Readonly;
use Repository::Simple::Permission;
use Repository::Simple::Util qw( normalize_path );
use Repository::Simple::Value;

our @CARP_NOT = qw( Repository::Simple::Util );

# $property = Repository::Simple::Property->new($node, $name)
#
# Create a new property object.
sub new {
    my ($class, $node, $name) = @_;
    return bless {
        node  => $node,
        name  => $name,
    }, $class;
}

sub parent {
    my $self = shift;
    return $self->{node};
}

sub name {
    my $self = shift;
    return $self->{name};
}

sub path {
    my $self = shift;
    return $self->{path} if $self->{path};
    return $self->{path} = normalize_path($self->{node}->path, $self->{name});
}

sub value {
    my $self = shift;
    return Repository::Simple::Value->new(
        $self->parent->repository, $self->path);
}

sub type {
    my $self = shift;
    return $self->engine->property_type_of($self->path);
}

sub engine {
    my $self = shift;
    return $self->{engine} if $self->{engine};
    return $self->{engine} = $self->{node}->repository->engine;
}

sub save {
    my $self = shift;
    my $path = $self->path;
    $self->parent->repository->check_permission($path, $SET_PROPERTY);
    return $self->engine->save_property($path);
}

1