Repository::Simple::Type::Property - Types for repository properties


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

Index


Code Index:

NAME

Top

Repository::Simple::Type::Property - Types for repository properties

SYNOPSIS

Top

See "SYNOPSIS" in Repository::Simple::Type::Node.

DESCRIPTION

Top

Property types are used to determine information about what kind of information is acceptable for a property and how it may be updated. This class provides a flexible way of describing the possible values, a method for marshalling and unmarshalling those values to and from a scalar for storage, and other metadata about possible values.

METHODS

$type = Repository::Simple::Type::Property->new(%args)

Creates a new property type with the given arguments, %args.

The following arguments are used:

engine (required)

This is a reference to the storage engine owning this property type.

name (required)

This is a short identifying name for the type. This should be a fully qualified name, e.g., "ns:name".

auto_created

This property should be set to true if the creation of a node containing a property of this type triggers the creation of a property of this type.

By default, this value is false.

updatable

This property should be set to true if the value stored in the property cannot be changed.

By default, this value is false.

removable

When this property is set to a true value, this property may not be set to undef or deleted.

By default, this value is false.

value_type

This property should be set to an instance of Repository::Simple::Type::Value for the type of value that is stored in it.

By default, this is set to an instance of Repository::Simple::Type::Value::Scalar.

$name = $type->name

This method returns the name of the type.

$auto_created = $type->auto_created

Returns a true value if the property is automatically created with the parent.

$updatable = $type->updatable

Returns a true value if the value may be changed.

$removable = $type->removable

Returns a true value if the value may be removed from it's parent node.

$value_type = $type->value_type

Returns the value type of the properties value.

AUTHOR

Top

Andrew Sterling Hanenkamp, <hanenkamp@cpan.org>

LICENSE AND COPYRIGHT

Top


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

use strict;
use warnings;

use Carp;

our $VERSION = '0.06';

use Repository::Simple::Type::Value::Scalar;
use Repository::Simple::Util;
use Scalar::Util qw( weaken );

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

sub new {
    my $class = shift;
    my %args  = @_;

    if (!defined $args{engine}) {
        croak 'The "engine" argument must be given.';
    }

    weaken $args{engine};

    if (!defined $args{name}) {
        croak 'The "name" argument must be given.';
    }

    $args{auto_created} ||= 0;
    $args{updatable}    ||= 0;
    $args{removable}    ||= 0;
    $args{value_type}   ||= Repository::Simple::Type::Value::Scalar->new;

    return bless \%args, $class;
}

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

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

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

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

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

1