| 1 | # | ||||||||||
| 2 | # This file is part of MooseX-Attribute-Deflator | ||||||||||
| 3 | # | ||||||||||
| 4 | # This software is Copyright (c) 2012 by Moritz Onken. | ||||||||||
| 5 | # | ||||||||||
| 6 | # This is free software, licensed under: | ||||||||||
| 7 | # | ||||||||||
| 8 | # The (three-clause) BSD License | ||||||||||
| 9 | # | ||||||||||
| 10 | package MooseX::Attribute::LazyInflator; | ||||||||||
| 11 | { | ||||||||||
| 12 | 5 | $MooseX::Attribute::LazyInflator::VERSION = '2.2.2'; | |||||||||
| 13 | } | ||||||||||
| 14 | |||||||||||
| 15 | # ABSTRACT: Lazy inflate attributes on access for better performance | ||||||||||
| 16 | |||||||||||
| 17 | 5 | ▶ | use Moose(); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 5 | ▶ | use MooseX::Attribute::Deflator (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 5 | ▶ | use Moose::Exporter; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 5 | ▶ | use Moose::Util (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 5 | ▶ | use MooseX::Attribute::LazyInflator::Meta::Role::Attribute; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 5 | ▶ | use MooseX::Attribute::LazyInflator::Meta::Role::ApplicationToClass; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 5 | ▶ | use MooseX::Attribute::LazyInflator::Meta::Role::ApplicationToRole; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | |||||||||||
| 25 | 5 | ▶ | Moose::Exporter->setup_import_methods( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | Moose->VERSION < 1.9900 | ||||||||||
| 27 | ? ( | ||||||||||
| 28 | class_metaroles => { | ||||||||||
| 29 | constructor => [ | ||||||||||
| 30 | 'MooseX::Attribute::LazyInflator::Meta::Role::Method::Constructor' | ||||||||||
| 31 | ], | ||||||||||
| 32 | } ) | ||||||||||
| 33 | : (), | ||||||||||
| 34 | role_metaroles => { | ||||||||||
| 35 | role => ['MooseX::Attribute::LazyInflator::Meta::Role::Role'], | ||||||||||
| 36 | application_to_class => | ||||||||||
| 37 | ['MooseX::Attribute::LazyInflator::Meta::Role::ApplicationToClass'], | ||||||||||
| 38 | application_to_role => | ||||||||||
| 39 | ['MooseX::Attribute::LazyInflator::Meta::Role::ApplicationToRole'], | ||||||||||
| 40 | }, | ||||||||||
| 41 | base_class_roles => ['MooseX::Attribute::LazyInflator::Role::Class'] ); | ||||||||||
| 42 | |||||||||||
| 43 | 5 | Moose::Util::_create_alias( 'Attribute', 'LazyInflator', 1, | |||||||||
| 44 | 'MooseX::Attribute::LazyInflator::Meta::Role::Attribute' ); | ||||||||||
| 45 | |||||||||||
| 46 | 5 | 1; | |||||||||
| 47 | |||||||||||
| 48 | |||||||||||
| 49 | |||||||||||
| 50 | =pod | ||||||||||
| 51 | |||||||||||
| 52 | =head1 NAME | ||||||||||
| 53 | |||||||||||
| 54 | MooseX::Attribute::LazyInflator - Lazy inflate attributes on access for better performance | ||||||||||
| 55 | |||||||||||
| 56 | =head1 VERSION | ||||||||||
| 57 | |||||||||||
| 58 | version 2.2.2 | ||||||||||
| 59 | |||||||||||
| 60 | =head1 SYNOPSIS | ||||||||||
| 61 | |||||||||||
| 62 | package Test; | ||||||||||
| 63 | |||||||||||
| 64 | use Moose; | ||||||||||
| 65 | use MooseX::Attribute::LazyInflator; | ||||||||||
| 66 | # Load default deflators and inflators | ||||||||||
| 67 | use MooseX::Attribute::Deflator::Moose; | ||||||||||
| 68 | |||||||||||
| 69 | has hash => ( is => 'rw', | ||||||||||
| 70 | isa => 'HashRef', | ||||||||||
| 71 | traits => ['LazyInflator'] ); | ||||||||||
| 72 | |||||||||||
| 73 | package main; | ||||||||||
| 74 | |||||||||||
| 75 | my $obj = Test->new( hash => '{"foo":"bar"}' ); | ||||||||||
| 76 | # Attribute 'hash' is being inflated to a HashRef on access | ||||||||||
| 77 | $obj->hash; | ||||||||||
| 78 | |||||||||||
| 79 | =head1 DESCRIPTION | ||||||||||
| 80 | |||||||||||
| 81 | Using C<coerce> will inflate an object on construction even if it is not needed. | ||||||||||
| 82 | This has the advantage, that type constraints are being called but on the other hand | ||||||||||
| 83 | it is rather slow. | ||||||||||
| 84 | |||||||||||
| 85 | This module will defer object inflation and constraint validation until it is first accessed. | ||||||||||
| 86 | Furthermore the advantages of C<inflate> apply as well. | ||||||||||
| 87 | |||||||||||
| 88 | =head1 SEE ALSO | ||||||||||
| 89 | |||||||||||
| 90 | =over 8 | ||||||||||
| 91 | |||||||||||
| 92 | =item L<MooseX::Attribute::LazyInflator::Role::Class> | ||||||||||
| 93 | |||||||||||
| 94 | =item MooseX::Attribute::LazyInflator::Meta::Role::Method::Accessor> | ||||||||||
| 95 | |||||||||||
| 96 | =item L<MooseX::Attribute::LazyInflator::Meta::Role::Method::Constructor> | ||||||||||
| 97 | |||||||||||
| 98 | =item L<MooseX::Attribute::Deflator/inflate> | ||||||||||
| 99 | |||||||||||
| 100 | =back | ||||||||||
| 101 | |||||||||||
| 102 | =head1 AUTHOR | ||||||||||
| 103 | |||||||||||
| 104 | Moritz Onken | ||||||||||
| 105 | |||||||||||
| 106 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 107 | |||||||||||
| 108 | This software is Copyright (c) 2012 by Moritz Onken. | ||||||||||
| 109 | |||||||||||
| 110 | This is free software, licensed under: | ||||||||||
| 111 | |||||||||||
| 112 | The (three-clause) BSD License | ||||||||||
| 113 | |||||||||||
| 114 | =cut | ||||||||||
| 115 | |||||||||||
| 116 | |||||||||||
| 117 | __END__ | ||||||||||