| 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::Meta::Role::Method::Accessor; | ||
| 11 | { | ||
| 12 | 1 | $MooseX::Attribute::LazyInflator::Meta::Role::Method::Accessor::VERSION = '2.2.2'; | |
| 13 | } | ||
| 14 | |||
| 15 | # ABSTRACT: Lazy inflate attributes | ||
| 16 | 1 | ▶ | use base 'Moose::Meta::Method::Accessor'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 17 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 18 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 19 | |||
| 20 | 0 | ▶ | sub _inline_check_lazy { |
|
Subroutine
_inline_check_lazy: not called CC=1 SCAR=6.9
| |||
| 21 | 0 | my ( $self, $instance ) = @_; | |
| 22 | 0 | my $slot_exists = $self->_inline_has($instance); | |
| 23 | 0 | my $code = "if($slot_exists && !\$attr->is_inflated($instance)) {\n "; | |
| 24 | 0 | $code .= "my \$inflated = \$attr->inflate($instance, " . $self->_inline_get($instance) . ");\n"; | |
| 25 | 0 | $code .= $self->_inline_check_coercion("\$inflated") . "\n"; | |
| 26 | 0 | $code .= $self->_inline_check_constraint("\$inflated") . "\n"; | |
| 27 | 0 | $code .= $self->_inline_store( $instance, "\$inflated" ) . "\n"; | |
| 28 | 0 | $code .= "}\n\n"; | |
| 29 | 0 | $code .= $self->next::method($instance); | |
| 30 | 0 | return $code; | |
| 31 | } | ||
| 32 | |||
| 33 | 1 | 1; | |
| 34 | |||
| 35 | |||
| 36 | |||
| 37 | =pod | ||
| 38 | |||
| 39 | =head1 NAME | ||
| 40 | |||
| 41 | MooseX::Attribute::LazyInflator::Meta::Role::Method::Accessor - Lazy inflate attributes | ||
| 42 | |||
| 43 | =head1 VERSION | ||
| 44 | |||
| 45 | version 2.2.2 | ||
| 46 | |||
| 47 | =head1 INHERITANCE | ||
| 48 | |||
| 49 | This class is a base class of L<Moose::Meta::Method::Accessor>. | ||
| 50 | |||
| 51 | This is subject to change. As the name suggests, it should be role. | ||
| 52 | |||
| 53 | =head1 METHODS | ||
| 54 | |||
| 55 | =over 8 | ||
| 56 | |||
| 57 | =item override B<_inline_check_lazy> | ||
| 58 | |||
| 59 | The attribute's value is being inflated and set if it has a value and hasn't been inflated yet. | ||
| 60 | |||
| 61 | =back | ||
| 62 | |||
| 63 | =head1 AUTHOR | ||
| 64 | |||
| 65 | Moritz Onken | ||
| 66 | |||
| 67 | =head1 COPYRIGHT AND LICENSE | ||
| 68 | |||
| 69 | This software is Copyright (c) 2012 by Moritz Onken. | ||
| 70 | |||
| 71 | This is free software, licensed under: | ||
| 72 | |||
| 73 | The (three-clause) BSD License | ||
| 74 | |||
| 75 | =cut | ||
| 76 | |||
| 77 | |||
| 78 | __END__ | ||