Data::Object::State

Singleton Builder for Perl 5

method: new method: renew

package Example;

use Data::Object::State;

has data => (
  is => 'ro'
);

package main;

my $example = Example->new;

This package provides an abstract base class for creating singleton classes. This package is derived from Moo and makes consumers Moo classes (with all that that entails). This package also injects a BUILD method which is responsible for hooking into the build process and returning the appropriate state.

The new method sets the internal state and returns a new class instance. Subsequent calls to new will return the same instance as was previously returned.

renew() : Object

=example-1 new

package Example::New;

use Data::Object::State;

has data => (
  is => 'ro'
);

my $example1 = Example::New->new(data => 'a');
my $example2 = Example::New->new(data => 'b');

[$example1, $example2]

The renew method resets the internal state and returns a new class instance. Each call to renew will discard the previous state, then reconstruct and stash the new state as requested.

renew() : Object

=example-1 renew

package Example::Renew;

use Data::Object::State;

has data => (
  is => 'ro'
);

my $example1 = Example::Renew->new(data => 'a');
my $example2 = $example1->renew(data => 'b');
my $example3 = Example::Renew->new(data => 'c');

[$example1, $example2, $example3]

9 POD Errors

The following errors were encountered while parsing the POD:

Around line 10:

Unknown directive: =name

Around line 16:

Unknown directive: =abstract

Around line 22:

Unknown directive: =includes

Around line 29:

Unknown directive: =synopsis

Around line 45:

Unknown directive: =description

Around line 55:

Unknown directive: =method

Around line 61:

Unknown directive: =signature

Around line 80:

Unknown directive: =method

Around line 86:

Unknown directive: =signature