| 1 | # | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # This file is part of MooseX-AutoDestruct | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # This software is Copyright (c) 2011 by Chris Weyl. | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # This is free software, licensed under: | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # The GNU Lesser General Public License, Version 2.1, February 1999 | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||
| 10 | package MooseX::AutoDestruct::V1::Trait::Method::Accessor; | ||||||||||||||||||||||||||||||||||||||||||
| 11 | { | ||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | $MooseX::AutoDestruct::V1::Trait::Method::Accessor::VERSION = '0.009'; | |||||||||||||||||||||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | # ABSTRACT: Accessor trait for Moose v1 | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | # debug! | ||||||||||||||||||||||||||||||||||||||||||
| 21 | #before _eval_closure => sub { print "$_[2]\n" }; | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | override _inline_pre_body => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | my ($self, $instance) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | my $attr = $self->associated_attribute; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | my $attr_name = $attr->name; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | my $mi = $attr->associated_class->instance_metaclass; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | my $code = super(); | |||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | my $type = $self->accessor_type; | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | return $code | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$type eq "accessor" or $type eq "reader" or $type eq "predicate"
$type eq "accessor" or $type eq "reader"
MC/DC0%0/3
$type eq "accessor" or $type eq "reader" or $type eq "predicate"
$type eq "accessor"
$type eq "reader"
$type eq "predicate"
Truth table0%0/4
A or B or C
A= $type eq "accessor"B= $type eq "reader"C= $type eq "predicate"
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | unless $type eq 'accessor' || $type eq 'reader' || $type eq 'predicate'; | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my $slot_exists = $self->_inline_has('$_[0]'); | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | $code .= "\n if ($slot_exists && time() > " | |||||||||||||||||||||||||||||||||||||||||
| 38 | . $mi->inline_get_slot_value('$_[0]', $attr->destruct_at_slot) | ||||||||||||||||||||||||||||||||||||||||||
| 39 | . ") {\n" | ||||||||||||||||||||||||||||||||||||||||||
| 40 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | if ($attr->has_clearer) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | # if we have a clearer method, we should call that -- it may have | ||||||||||||||||||||||||||||||||||||||||||
| 45 | # been wrapped in the class | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $clearer = $attr->clearer; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | ($clearer) = keys %$clearer if ref $clearer; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $code .= '$_[0]->' . $clearer . '()'; | |||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | # otherwise, just deinit all the slots we use | ||||||||||||||||||||||||||||||||||||||||||
| 56 | $code .= ' ' .$mi->inline_deinitialize_slot('$_[0]', $_) . ";\n" | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | for $attr->slots; | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | $code .= "}\n"; | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | return $code; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | override _generate_predicate_method_inline => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | my $attr = $self->associated_attribute; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | my $attr_name = $attr->name; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | my $meta_instance = $attr->associated_class->instance_metaclass; | |||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my ( $code, $e ) = $self->_eval_closure( | |||||||||||||||||||||||||||||||||||||||||
| 72 | {}, | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 'sub {' | ||||||||||||||||||||||||||||||||||||||||||
| 74 | . $self->_inline_pre_body(@_) | ||||||||||||||||||||||||||||||||||||||||||
| 75 | . $meta_instance->inline_is_slot_initialized('$_[0]', $attr->value_slot) | ||||||||||||||||||||||||||||||||||||||||||
| 76 | . $self->_inline_post_body(@_) | ||||||||||||||||||||||||||||||||||||||||||
| 77 | . '}' | ||||||||||||||||||||||||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | confess "Could not generate inline predicate because : $e" if $e; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | return $code; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | override _generate_clearer_method_inline => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | my $attr = $self->associated_attribute; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my $attr_name = $attr->name; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my $mi = $attr->associated_class->instance_metaclass; | |||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my $deinit; | |||||||||||||||||||||||||||||||||||||||||
| 91 | $deinit .= $mi->inline_deinitialize_slot('$_[0]', $_) . ';' | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | for $attr->slots; | |||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my ( $code, $e ) = $self->_eval_closure( | |||||||||||||||||||||||||||||||||||||||||
| 95 | {}, | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 'sub {' | ||||||||||||||||||||||||||||||||||||||||||
| 97 | . $self->_inline_pre_body(@_) | ||||||||||||||||||||||||||||||||||||||||||
| 98 | . $deinit | ||||||||||||||||||||||||||||||||||||||||||
| 99 | . $self->_inline_post_body(@_) | ||||||||||||||||||||||||||||||||||||||||||
| 100 | . '}' | ||||||||||||||||||||||||||||||||||||||||||
| 101 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | confess "Could not generate inline clearer because : $e" if $e; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | return $code; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | # we need to override/wrap _inline_store() so we can deal with there being | ||||||||||||||||||||||||||||||||||||||||||
| 108 | # two valid slots here that mean two different things: the value and when | ||||||||||||||||||||||||||||||||||||||||||
| 109 | # it autodestructs. | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | override _inline_store => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my ($self, $instance, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my $attr = $self->associated_attribute; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my $mi = $attr->associated_class->get_meta_instance; | |||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my $code = $mi->inline_set_slot_value($instance, $attr->value_slot, $value); | |||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | $code .= ";\n "; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | $code .= $self->_inline_set_doomsday($instance); | |||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | $code .= $mi->inline_weaken_slot_value($instance, $attr->value_slot, $value) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | if $attr->is_weak_ref; | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | return $code; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | sub _inline_set_doomsday { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_inline_set_doomsday: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | my ($self, $instance) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | my $attr = $self->associated_attribute; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | my $mi = $attr->associated_class->get_meta_instance; | |||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my $code = $mi->inline_set_slot_value( | |||||||||||||||||||||||||||||||||||||||||
| 131 | $instance, | ||||||||||||||||||||||||||||||||||||||||||
| 132 | $attr->destruct_at_slot, | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 'time() + ' . $attr->ttl, | ||||||||||||||||||||||||||||||||||||||||||
| 134 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | return "$code;\n"; | |||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | !!42; | |||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | MooseX::AutoDestruct::V1::Trait::Method::Accessor - Accessor trait for Moose v1 | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | version 0.009 | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | Implementation attribute trait of L<MooseX::AutoDestruct> for L<Moose> version | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 1.xx. | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | L<MooseX:AutoDestruct>. | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | Chris Weyl <cweyl@alumni.drew.edu> | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | This software is Copyright (c) 2011 by Chris Weyl. | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | This is free software, licensed under: | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | The GNU Lesser General Public License, Version 2.1, February 1999 | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | __END__ | ||||||||||||||||||||||||||||||||||||||||||