1 package MooseX::Storage::Engine::Trait::OnlyWhenBuilt;
5 # only serialize the attribute if it's already built. So, go ahead
6 # and check if the attribute has a predicate. If so, check if it's
7 # set and then go ahead and look it up.
8 around 'collapse_attribute' => sub {
9 my ($orig, $self, $attr, @args) = @_;
11 my $pred = $attr->predicate if $attr->has_predicate;
13 return () unless $self->object->$pred();
16 return $self->$orig($attr, @args);