Commit | Line | Data |
a473d69d |
1 | package MooseX::Storage::Engine::Trait::OnlyWhenBuilt; |
2 | use Moose::Role; |
3 | |
4eafd265 |
4 | # we should |
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) = @_; |
10 | |
11 | my $pred = $attr->predicate if $attr->has_predicate; |
12 | if ($pred) { |
13 | return () unless $self->object->$pred(); |
14 | } |
15 | |
16 | return $self->$orig($attr, @args); |
17 | }; |
a473d69d |
18 | |
19 | 1; |
20 | |