File Coverage

blib/lib/MooseX/Attribute/LazyInflator.pm
Criterion Covered Total %
statement 21 21 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod n/a
total 28 28 100.0


line stmt bran cond sub pod time code
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             $MooseX::Attribute::LazyInflator::VERSION = '2.1.11'; # TRIAL
13             }
14              
15             # ABSTRACT: Lazy inflate attributes on access for better performance
16              
17 4     4   1759092 use Moose();
  4         5  
  4         80  
18 4     4   1025 use MooseX::Attribute::Deflator ();
  4         12  
  4         102  
19 4     4   19 use Moose::Exporter;
  4         4  
  4         18  
20 4     4   134 use Moose::Util ();
  4         5  
  4         51  
21 4     4   2049 use MooseX::Attribute::LazyInflator::Meta::Role::Attribute;
  4         9  
  4         127  
22 4     4   1655 use MooseX::Attribute::LazyInflator::Meta::Role::ApplicationToClass;
  4         7  
  4         113  
23 4     4   1574 use MooseX::Attribute::LazyInflator::Meta::Role::ApplicationToRole;
  4         9  
  4         343  
24              
25             Moose::Exporter->setup_import_methods(
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             Moose::Util::_create_alias( 'Attribute', 'LazyInflator', 1,
44             'MooseX::Attribute::LazyInflator::Meta::Role::Attribute' );
45              
46             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.1.11
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__
118              
119