- Notifications
You must be signed in to change notification settings - Fork0
Minimalist Object Persistence
License
awncorp/nano
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
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; # 0my $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 ontheZing toolkit which provides pluggable storage and serialization options.
This package uses type constraints from:
This package has the following attributes:
env(Env)This attribute is read-only, accepts(Env) values, and is optional.
This package implements the following methods:
domain(Str $name) : DomainThe domain method returns aZing::Domain object for the ID provided.
domain example #1
my $nano = Nano->new; my $domain = $nano->domain('changelog');
dump(Object $object) : HashRefThe dump method returns a serialized hash representation for the objectprovided.
dump example #1
my $nano = Nano->new; my $rachel = $nano->find('rachel'); my $dump = $nano->dump($rachel);
find(Str $name) : NodeThe find method finds, inflates, and returns a prior persisted object for theID provided.
find example #1
my $nano = Nano->new; my $phoebe = $nano->find('phoebe');
hash(Str $name) : StrThe hash method returns a SHA-1 digest for the string provided.
hash example #1
my $nano = Nano->new; my $email = 'me@example.com'; $nano->hash($email);
keyval(Str $name) : KeyValThe keyval method returns aZing::KeyVal object for the ID provided.
keyval example #1
my $nano = Nano->new; my $keyval = $nano->keyval('rachel');
name(Object $object) : StrThe name method returns the class name for the object provided.
name example #1
my $nano = Nano->new; my $rachel = $nano->find('rachel'); my $name = $nano->name($rachel);
object(HashRef $object) : ObjectThe object method returns an object derived from a prior serializationrepresentation.
object example #1
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) : ObjectThe reify method constructs an object from the class name and data provided.
reify example #1
my $nano = Nano->new; my $new_rachel = $nano->reify('Person', { id => 'rachel', name => 'rachel', });
table(Str $name) : TableThe table method returns aZing::Table object for the ID provided.
table example #1
my $nano = Nano->new; my $rachel = $nano->find('rachel'); my $table = $nano->table($rachel->friends->id);
Al Newkirk,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 termsof the The Apache License, Version 2.0, as elucidated in the"licensefile".
About
Minimalist Object Persistence
Topics
Resources
License
Code of conduct
Contributing
Uh oh!
There was an error while loading.Please reload this page.