Nano
Object Persistence
Minimalist Object Persistence
method: domain method: dump method: hash method: find method: keyval method: name method: object method: reify method: table
package Person;
use Moo;
extends 'Nano::Node';
has name => (
is => 'ro',
required => 1,
);
has friends => (
is => 'ro',
default => sub { People->new }
);
sub extroverted {
my ($self) = @_;
($self->friends->count > 1) ? 1 : 0
}
sub introverted {
my ($self) = @_;
($self->friends->count < 2) ? 1 : 0
}
package People;
use Moo;
extends 'Nano::Nodes';
sub new_type {
'Person'
}
sub extroverted {
my ($self) = @_;
$self->scope(sub {
my ($person) = @_;
$person->extroverted
});
}
sub introverted {
my ($self) = @_;
$self->scope(sub {
my ($person) = @_;
$person->introverted
});
}
package main;
my $rachel = Person->new(
id => 'rachel',
name => 'rachel',
);
my $monica = Person->new(
id => 'monica',
name => 'monica',
);
my $phoebe = Person->new(
id => 'phoebe',
name => 'phoebe',
);
$rachel->friends->set($monica);
$rachel->friends->set($phoebe);
$monica->friends->set($rachel);
$monica->friends->set($phoebe);
$phoebe->friends->set($rachel);
$phoebe->friends->set($monica);
$rachel->save;
$monica->save;
$phoebe->save;
$phoebe->friends->count; # 2
$phoebe->friends->extroverted->count; # 2
$phoebe->friends->introverted->count; # 0
my $nano = Nano->new;
my $friend = $nano->find('rachel');
Nano::Types
env: ro, opt, Env
This package provides a minimalist framework for persisting objects (i.e. class instances) with as little effort as possible. This framework relies on the Zing toolkit which provides pluggable storage and serialization options.
The domain method returns a Zing::Domain object for the ID provided.
domain(Str $name) : Domain
=example-1 domain
my $nano = Nano->new;
my $domain = $nano->domain('changelog');
The keyval method returns a Zing::KeyVal object for the ID provided.
keyval(Str $name) : KeyVal
=example-1 keyval
my $nano = Nano->new;
my $keyval = $nano->keyval('rachel');
The dump method returns a serialized hash representation for the object provided.
dump(Object $object) : HashRef
=example-1 dump
my $nano = Nano->new;
my $rachel = $nano->find('rachel');
my $dump = $nano->dump($rachel);
The hash method returns a SHA-1 digest for the string provided.
hash(Str $name) : Str
=example-1 hash
my $nano = Nano->new;
my $email = 'me@example.com';
$nano->hash($email);
The find method finds, inflates, and returns a prior persisted object for the ID provided.
find(Str $name) : Node
=example-1 find
my $nano = Nano->new;
my $phoebe = $nano->find('phoebe');
The table method returns a Zing::Table object for the ID provided.
table(Str $name) : Table
=example-1 table
my $nano = Nano->new;
my $rachel = $nano->find('rachel');
my $table = $nano->table($rachel->friends->id);
The name method returns the class name for the object provided.
name(Object $object) : Str
=example-1 name
my $nano = Nano->new;
my $rachel = $nano->find('rachel');
my $name = $nano->name($rachel);
The object method returns an object derived from a prior serialization representation.
object(HashRef $object) : Object
=example-1 object
my $nano = Nano->new;
my $new_rachel = $nano->object({
'$type' => 'node',
'$name' => 'Person',
'$data' => {
'id' => 'rachel',
'name' => 'rachel',
'nano' => {
'$skip' => 1
},
'friends' => {
'$skip' => 1
},
},
});
The reify method constructs an object from the class name and data provided.
reify(Str $name, HashRef $data) : Object
=example-1 reify
my $nano = Nano->new;
my $new_rachel = $nano->reify('Person', {
id => 'rachel',
name => 'rachel',
});
26 POD Errors
The following errors were encountered while parsing the POD:
- Around line 10:
Unknown directive: =name
- Around line 16:
Unknown directive: =tagline
- Around line 22:
Unknown directive: =abstract
- Around line 28:
Unknown directive: =includes
- Around line 42:
Unknown directive: =synopsis
- Around line 136:
Unknown directive: =libraries
- Around line 142:
Unknown directive: =attributes
- Around line 148:
Unknown directive: =description
- Around line 156:
Unknown directive: =method
- Around line 160:
Unknown directive: =signature
- Around line 172:
Unknown directive: =method
- Around line 176:
Unknown directive: =signature
- Around line 188:
Unknown directive: =method
- Around line 193:
Unknown directive: =signature
- Around line 207:
Unknown directive: =method
- Around line 211:
Unknown directive: =signature
- Around line 225:
Unknown directive: =method
- Around line 230:
Unknown directive: =signature
- Around line 242:
Unknown directive: =method
- Around line 246:
Unknown directive: =signature
- Around line 260:
Unknown directive: =method
- Around line 264:
Unknown directive: =signature
- Around line 278:
Unknown directive: =method
- Around line 283:
Unknown directive: =signature
- Around line 308:
Unknown directive: =method
- Around line 312:
Unknown directive: =signature