Skip to content

Commit

Permalink
Fix for Moose 1.900+ , but should work since Class::MOP 5e5102f19ccb1…
Browse files Browse the repository at this point in the history
…dc52b290577b0363e97dacbd5b3, sadly, this never made it out as its own Class::MOP release :(
  • Loading branch information
kentfredric authored and rjbs committed Feb 5, 2011
1 parent 466aff3 commit b158831
Showing 1 changed file with 5 additions and 24 deletions.
29 changes: 5 additions & 24 deletions lib/MooseX/SetOnce.pm
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,11 @@ sub _ensure_unset {
if $self->has_value($instance);
}

around accessor_metaclass => sub {
my ($orig, $self, @rest) = @_;

return Moose::Meta::Class->create_anon_class(
superclasses => [ $self->$orig(@_) ],
roles => [ 'MooseX::SetOnce::Accessor' ],
cache => 1
)->name
};

package MooseX::SetOnce::Accessor;
use Moose::Role 0.90;

around _inline_store => sub {
my ($orig, $self, $instance, $value) = @_;

my $code = $self->$orig($instance, $value);
$code = sprintf qq[%s->meta->get_attribute("%s")->_ensure_unset(%s);\n%s],
$instance,
quotemeta($self->associated_attribute->name),
$instance,
$code;

return $code;
around _inline_set_value => sub {
my ( $orig, $self, @args ) = @_;
my (@lines) = $self->$orig(@args);
unshift @lines, sprintf q{$_[0]->meta->get_attribute("%s")->_ensure_unset($_[0]);}, quotemeta( $self->name );
return @lines;
};

package Moose::Meta::Attribute::Custom::Trait::SetOnce;
Expand Down

0 comments on commit b158831

Please sign in to comment.