The Perl Toolchain Summit 2025 Needs You: You can help 🙏 Learn more

NAME

MooseX::Attribute::LazyInflator - Lazy inflate attributes on access for better performance

VERSION

version 2.2.2

SYNOPSIS

package Test;
use Moose;
# Load default deflators and inflators
has hash => ( is => 'rw',
isa => 'HashRef',
traits => ['LazyInflator'] );
package main;
my $obj = Test->new( hash => '{"foo":"bar"}' );
# Attribute 'hash' is being inflated to a HashRef on access
$obj->hash;

DESCRIPTION

Using coerce will inflate an object on construction even if it is not needed. This has the advantage, that type constraints are being called but on the other hand it is rather slow.

This module will defer object inflation and constraint validation until it is first accessed. Furthermore the advantages of inflate apply as well.

SEE ALSO

MooseX::Attribute::LazyInflator::Role::Class
MooseX::Attribute::LazyInflator::Meta::Role::Method::Accessor>
MooseX::Attribute::LazyInflator::Meta::Role::Method::Constructor
"inflate" in MooseX::Attribute::Deflator

AUTHOR

Moritz Onken

COPYRIGHT AND LICENSE

This software is Copyright (c) 2012 by Moritz Onken.

This is free software, licensed under:

The (three-clause) BSD License