File Coverage

blib/lib/MooseX/Storage/Engine/Trait/WithRoles.pm
Criterion Covered Total %
statement 18 18 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 24 24 100.0


line stmt bran cond sub pod time code
1             package MooseX::Storage::Engine::Trait::WithRoles;
2             our $AUTHORITY = 'cpan:YANICK';
3             # ABSTRACT: An engine trait to include roles in serialization
4             $MooseX::Storage::Engine::Trait::WithRoles::VERSION = '0.2.0';
5 3     3   10068 use Moose::Util qw/ with_traits /;
  3         8  
  3         28  
6              
7 3     3   784 use List::Util qw/ pairgrep /;
  3         7  
  3         218  
8              
9 3     3   16 use Moose::Role;
  3         6  
  3         30  
10 3     3   15517 use MooseX::Storage::Base::SerializedClass;
  3         6  
  3         141  
11 3     3   16 use List::MoreUtils qw/ apply /;
  3         7  
  3         98  
12              
13 3     3   1287 use namespace::autoclean;
  3         5  
  3         26  
14              
15             around collapse_object => sub {
16             my( $orig, $self, @args ) = @_;
17              
18             my $packed = $orig->( $self, @args );
19              
20             my @extra;
21             ( $packed->{'__CLASS__'}, @extra ) = split '\|', ($self->object->meta->superclasses)[0]
22             if $self->object->meta->is_anon_class or $self->object->meta->name =~ /__ANON__/ ;
23              
24             my %in_superclass = map { $_ => 1 } map { split '\|', $_->name } @{ $packed->{'__CLASS__'}->meta->roles };
25              
26             if( my @roles = grep { !$in_superclass{$_} } map { split '\|', } ( @extra, map { $_->name } @{ $self->object->meta->roles } ) ) {
27             @roles = apply {
28             $_ = { $_->meta->genitor->name => { pairgrep { $a ne '<<MOP>>' } %{ $_->meta->parameters } } }
29             if $_->meta->isa('MooseX::Role::Parameterized::Meta::Role::Parameterized')
30             } @roles;
31             $packed->{'__ROLES__'} = \@roles;
32             }
33              
34              
35             return $packed;
36             };
37              
38             around expand_object => sub {
39             my( $orig, $self, $data, @args ) = @_;
40              
41             $self->class(
42             MooseX::Storage::Base::SerializedClass::_unpack_class($data)
43             );
44              
45             $orig->($self,$data,@args);
46             };
47              
48             1;
49              
50             __END__
51              
52             =pod
53              
54             =encoding UTF-8
55              
56             =head1 NAME
57              
58             MooseX::Storage::Engine::Trait::WithRoles - An engine trait to include roles in serialization
59              
60             =head1 VERSION
61              
62             version 0.2.0
63              
64             =head1 AUTHOR
65              
66             Yanick Champoux <yanick@babyl.dyndns.org>
67              
68             =head1 COPYRIGHT AND LICENSE
69              
70             This software is copyright (c) 2015 by Yanick Champoux.
71              
72             This is free software; you can redistribute it and/or modify it under
73             the same terms as the Perl 5 programming language system itself.
74              
75             =cut