NAME

Nano::Nodes - Persistable Index

ABSTRACT

Persistable Index Super Class

SYNOPSIS

use Nano::Nodes;

my $nodes = Nano::Nodes->new(
  type => 'Nano::Node',
);

# $nodes->save;

DESCRIPTION

This package provides a persistable index super class. It is meant to be subclassed but can be used directly as well.

INHERITS

This package inherits behaviors from:

Nano::Node

LIBRARIES

This package uses type constraints from:

Nano::Types

ATTRIBUTES

This package has the following attributes:

scopes

scopes(ArrayRef[CodeRef])

This attribute is read-only, accepts (ArrayRef[CodeRef]) values, and is optional.

type

type(Str)

This attribute is read-only, accepts (Str) values, and is required.

METHODS

This package implements the following methods:

add

add(HashRef $data) : Object

The add method creates a new object, adds it to the index, and returns the created object.

add example #1
# given: synopsis

my $node = $nodes->add({ rand => time });

all

all() : ArrayRef[Object]

The all method proxies to the attached Nano::Search instance and returns the results.

all example #1
# given: synopsis

my $all = $nodes->all;

count

count() : Int

The count method proxies to the attached Nano::Search instance and returns the results.

count example #1
# given: synopsis

my $count = $nodes->count;

del

del(Str $name) : Maybe[Object]

The del method removes the object from the index and returns the object (if found).

del example #1
# given: synopsis

my $result = $nodes->del('0000001');

drop

drop() : Object

The drop method deletes the entire index and all of its indices.

drop example #1
# given: synopsis

$nodes = $nodes->drop;

first

first() : Maybe[Object]

The first method proxies to the attached Nano::Search instance and returns the result.

first example #1
# given: synopsis

my $first = $nodes->first;

get

get(Str $name) : Maybe[Object]

The get method returns the object (based on ID) from the index (if found).

get example #1
# given: synopsis

my $result = $nodes->get('0000001');

last

last() : Maybe[Object]

The last method proxies to the attached Nano::Search instance and returns the result.

last example #1
# given: synopsis

my $last = $nodes->last;

next

next() : Maybe[Object]

The next method proxies to the attached Nano::Search instance and returns the result.

next example #1
# given: synopsis

my $next = $nodes->next;

prev

prev() : Maybe[Object]

The prev method proxies to the attached Nano::Search instance and returns the result.

prev example #1
# given: synopsis

my $prev = $nodes->prev;

scope

scope(CodeRef $callback) : Object

The scope method registers a scope (search filter) and returns a new invocant instance.

scope example #1
# given: synopsis

$nodes = $nodes->scope(sub {
  my ($node) = @_;

  !!$node->{active}
});
search() : Search

The search method returns a Nano::Search object associated with the invocant.

search example #1
# given: synopsis

my $search = $nodes->search;

serialize

serialize() : HashRef

The serialize method returns a persistence representaton of the invocant. Circular dependencies can result in a deep recursion error, however, circular dependencies can be persisted if modeled properly. Note: blessed objects which are neither Nano::Node nor Nano::Nodes will be ignored.

serialize example #1
# given: synopsis

my $serial = $nodes->serialize;

set

set(Node $object) : Object

The set method adds the node object provided to the index and returns the provided object.

set example #1
# given: synopsis

use Nano::Node;

my $node = Nano::Node->new(id => '0000003');

$node = $nodes->set($node);

AUTHOR

Al Newkirk, awncorp@cpan.org

LICENSE

Copyright (C) 2011-2019, Al Newkirk, et al.

This is free software; you can redistribute it and/or modify it under the terms of the The Apache License, Version 2.0, as elucidated in the "license file".

PROJECT

Wiki

Project

Initiatives

Milestones

Contributing

Issues