Giter Site home page Giter Site logo

nano's Introduction

NAME

Nano - Object Persistence

ABSTRACT

Minimalist Object Persistence

SYNOPSIS

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');

DESCRIPTION

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.

LIBRARIES

This package uses type constraints from:

Nano::Types

ATTRIBUTES

This package has the following attributes:

env

env(Env)

This attribute is read-only, accepts (Env) values, and is optional.

METHODS

This package implements the following methods:

domain

domain(Str $name) : Domain

The domain method returns a Zing::Domain object for the ID provided.

  • domain example #1

      my $nano = Nano->new;
    
      my $domain = $nano->domain('changelog');
    

dump

dump(Object $object) : HashRef

The dump method returns a serialized hash representation for the object provided.

  • dump example #1

      my $nano = Nano->new;
    
      my $rachel = $nano->find('rachel');
    
      my $dump = $nano->dump($rachel);
    

find

find(Str $name) : Node

The find method finds, inflates, and returns a prior persisted object for the ID provided.

  • find example #1

      my $nano = Nano->new;
    
      my $phoebe = $nano->find('phoebe');
    

hash

hash(Str $name) : Str

The hash method returns a SHA-1 digest for the string provided.

  • hash example #1

      my $nano = Nano->new;
    
      my $email = '[email protected]';
    
      $nano->hash($email);
    

keyval

keyval(Str $name) : KeyVal

The keyval method returns a Zing::KeyVal object for the ID provided.

  • keyval example #1

      my $nano = Nano->new;
    
      my $keyval = $nano->keyval('rachel');
    

name

name(Object $object) : Str

The 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

object(HashRef $object) : Object

The object method returns an object derived from a prior serialization representation.

  • 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

reify(Str $name, HashRef $data) : Object

The 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

table(Str $name) : Table

The table method returns a Zing::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);
    

AUTHOR

Al Newkirk, [email protected]

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

nano's People

Stargazers

 avatar

Watchers

 avatar

nano's Issues

Document backlinks architecture

E.g.

package Leaf;

use Moo;

extends 'Nano::Node';

has backlinks => (
  is => 'ro',
  default => sub {{}},
);

sub get {
  my ($self, $name) = @_;
  $self->nano->find($self->backlinks->{$name})
}

sub set {
  my ($self, $name, $node) = @_;
  $self->backlinks->{$name} = $node->id;
  $node
}

1;

Implement Nano::Stash

Nano::Stash will be a simple role included in the distribution, e.g. with 'Nano::Stash', which provides a stashed attribute, a stash method, as well as get and set methods, which allows Nano::Node derived classes to attach other Nano::Node derived classes by ID. Attaching by ID means circular references are gracefully handled.

Implement Nano::Env

Nano::Env to subclass Zing::Env specifically to enforce setting the system variable to "nano".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.