The Perl Advent Calendar needs more articles for 2022. Submit your idea today!

NAME

Venus::Role::Stashable - Stashable Role

ABSTRACT

Stashable Role for Perl 5

SYNOPSIS

  package Example;

  use Venus::Class;

  with 'Venus::Role::Stashable';

  attr 'test';

  package main;

  my $example = Example->new(test => time);

  # $example->stash;

DESCRIPTION

This package modifies the consuming package and provides methods for stashing data within the object.

METHODS

This package provides the following methods:

stash

  stash(Any $key, Any $value) (Any)

The stash method is used to fetch and stash named values associated with the object. Calling this method without arguments returns all values.

Since 0.01

stash example 1
  package main;

  my $example = Example->new(test => time);

  my $stash = $example->stash;

  # {}
stash example 2
  package main;

  my $example = Example->new(test => time);

  my $stash = $example->stash('test', {1..4});

  # { 1 => 2, 3 => 4 }
stash example 3
  package main;

  my $example = Example->new(test => time);

  my $stash = $example->stash('test');

  # undef