Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Minimalist Object Persistence

License

NotificationsYou must be signed in to change notification settings

awncorp/nano

Repository files navigation

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; # 0my $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 ontheZing 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 aZing::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 objectprovided.

  • 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 theID 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 = 'me@example.com';  $nano->hash($email);

keyval

keyval(Str $name) : KeyVal

The keyval method returns aZing::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 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

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

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 termsof the The Apache License, Version 2.0, as elucidated in the"licensefile".

PROJECT

Wiki

Project

Initiatives

Milestones

Contributing

Issues


[8]ページ先頭

©2009-2025 Movatter.jp