The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Data::Object::State

ABSTRACT

Singleton Builder for Perl 5

SYNOPSIS

  package Example;

  use Data::Object::State;

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

  package main;

  my $example = Example->new;

DESCRIPTION

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.

METHODS

This package implements the following methods:

new

  renew() : Object

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.

new example #1
  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]

renew

  renew() : Object

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 example #1
  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]

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".

PROJECT

Wiki

Project

Initiatives

Milestones

Contributing

Issues