Nano - Object Persistence
Minimalist Object Persistence
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');
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.
This package uses type constraints from:
Nano::Types
This package has the following attributes:
env(Env)
This attribute is read-only, accepts (Env) values, and is optional.
(Env)
This package implements the following methods:
domain(Str $name) : Domain
The domain method returns a Zing::Domain object for the ID provided.
my $nano = Nano->new; my $domain = $nano->domain('changelog');
dump(Object $object) : HashRef
The dump method returns a serialized hash representation for the object provided.
my $nano = Nano->new; my $rachel = $nano->find('rachel'); my $dump = $nano->dump($rachel);
find(Str $name) : Node
The find method finds, inflates, and returns a prior persisted object for the ID provided.
my $nano = Nano->new; my $phoebe = $nano->find('phoebe');
hash(Str $name) : Str
The hash method returns a SHA-1 digest for the string provided.
my $nano = Nano->new; my $email = 'me@example.com'; $nano->hash($email);
keyval(Str $name) : KeyVal
The keyval method returns a Zing::KeyVal object for the ID provided.
my $nano = Nano->new; my $keyval = $nano->keyval('rachel');
name(Object $object) : Str
The name method returns the class name for the object provided.
my $nano = Nano->new; my $rachel = $nano->find('rachel'); my $name = $nano->name($rachel);
object(HashRef $object) : Object
The object method returns an object derived from a prior serialization representation.
my $nano = Nano->new; my $new_rachel = $nano->object({ '$type' => 'node', '$name' => 'Person', '$data' => { 'id' => 'rachel', 'name' => 'rachel', 'nano' => { '$skip' => 1 }, 'friends' => { '$skip' => 1 }, }, });
reify(Str $name, HashRef $data) : Object
The reify method constructs an object from the class name and data provided.
my $nano = Nano->new; my $new_rachel = $nano->reify('Person', { id => 'rachel', name => 'rachel', });
table(Str $name) : Table
The table method returns a Zing::Table object for the ID provided.
my $nano = Nano->new; my $rachel = $nano->find('rachel'); my $table = $nano->table($rachel->friends->id);
Al Newkirk, awncorp@cpan.org
awncorp@cpan.org
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".
Wiki
Project
Initiatives
Milestones
Contributing
Issues
To install Nano, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Nano
CPAN shell
perl -MCPAN -e shell install Nano
For more information on module installation, please visit the detailed CPAN module installation guide.