NAME
Nano::Track - Trackable Role
ABSTRACT
Trackable Entity Role
SYNOPSIS
package Example;
use Moo;
extends 'Nano::Node';
with 'Nano::Track';
sub creator {
my ($self, @args) = @_;
return $self->getset('creator', @args);
}
sub touched {
my ($self, @args) = @_;
return $self->incr('touched');
}
package main;
my $example = Example->new;
# $example->touched;
DESCRIPTION
This package provides a transactional change-tracking role, useful for creating a history of changes and/or preventing race conditions when saving data for Nano::Node entities. Note: Due to conflicting method names, this role cannot be used with the Nano::Stash role.
LIBRARIES
This package uses type constraints from:
ATTRIBUTES
This package has the following attributes:
changed
changed(Changes)
This attribute is read-only, accepts (Changes)
values, and is optional.
METHODS
This package implements the following methods:
decr
decr(Str $name) : Int
The decr method decrements the data associated with a specific key.
- decr example #2
-
my $example = Example->new; $example->incr('upvote'); $example->incr('upvote'); $example->incr('upvote'); my $upvote = $example->decr('upvote');
del
del(Str $name) : Any
The del method deletes the data associated with a specific key.
- del example #2
-
my $example = Example->new; $example->set('touched', 'monday'); my $touched = $example->del('touched');
get
get($name) : Any
The get method return the data associated with a specific key.
- get example #2
-
my $example = Example->new; $example->set('profile', { nickname => 'demonstration', }); my $profile = $example->get('profile');
getpush
getpush(Str $name, Any @args) : ArrayRef[Any] | Any
The getpush method calls "push" or "get" based on the arguments provided. Allows you to easily create method-based accessors.
getset
getset(Str $name, Any @args) : Any
The getset method calls "get" or "set" based on the arguments provided. Allows you to easily create method-based accessors.
- getset example #1
-
my $example = Example->new; my $profile = $example->getset('profile', { nickname => 'demonstration', });
- getset example #2
-
my $example = Example->new; $example->getset('profile', { nickname => 'demonstration', }); my $profile = $example->getset('profile');
getunshift
getunshift(Str $name, Any @args) : ArrayRef[Any] | Any
The getunshift method calls "unshift" or "get" based on the arguments provided. Allows you to easily create method-based accessors.
- getunshift example #2
-
my $example = Example->new; $example->set('steps', ['#0']); my $step = $example->getunshift('steps', '#1', '#2');
incr
incr(Str $name) : Int
The incr method increments the data associated with a specific key.
- incr example #2
-
my $example = Example->new; $example->incr('upvote'); $example->incr('upvote'); my $upvote = $example->incr('upvote');
merge
merge(Str $name, HashRef $value) : HashRef
The merge method commits the data associated with a specific key to the channel as a partial to be merged into any existing data.
- merge example #1
-
my $example = Example->new; my $merge = $example->merge('profile', { password => 's3crets', });
- merge example #2
-
my $example = Example->new; $example->set('profile', { nickname => 'demonstration', }); my $merge = $example->merge('profile', { password => 's3crets', });
pop
pop(Str $name) : Any
The pop method pops the data off of the stack associated with a specific key.
- pop example #2
-
my $example = Example->new; $example->push('steps', '#1', '#2'); my $steps = $example->pop('steps');
poppush
poppush(Str $name, Any @args) : ArrayRef[Any] | Any
The poppush method calls "push" or "pop" based on the arguments provided. Allows you to easily create method-based accessors.
- poppush example #2
-
my $example = Example->new; $example->set('steps', ['#1', '#2', '#3']); my $steps = $example->poppush('steps', '#4');
- poppush example #3
-
my $example = Example->new; $example->set('steps', ['#1', '#2', '#3']); my $steps = $example->poppush('steps');
push
push(Str $name, Any @value) : ArrayRef[Any]
The push method pushes data onto the stack associated with a specific key.
set
set(Str $name, Any @args) : Any
The set method commits the data associated with a specific key to the channel.
- set example #2
-
my $example = Example->new; my $email = $example->set('email', 'try@example.com', 'retry@example.com');
shift
shift(Str $name) : Any
The shift method shifts data off of the stack associated with a specific key.
- shift example #2
-
my $example = Example->new; $example->set('steps', ['#1', '#2', '#3']); my $steps = $example->shift('steps');
shiftunshift
shiftunshift(Str $name, Any @args) : ArrayRef[Any] | Any
The shiftunshift method calls "unshift" or "shift" based on the arguments provided. Allows you to easily create method-based accessors.
- shiftunshift example #2
-
my $example = Example->new; my $steps = $example->shiftunshift('steps', '#1', '#2');
unshift
unshift(Str $name, Any @value) : ArrayRef[Any] | Any
The unshift method unshifts data onto the stack associated with a specific key.
- unshift example #2
-
my $example = Example->new; my $arguments = $example->unshift('steps', '#1', '#2');
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 terms of the The Apache License, Version 2.0, as elucidated in the "license file".