| 1 | #!/usr/bin/perl | ||||||||||
| 2 | |||||||||||
| 3 | package KiokuDB::TypeMap::Entry::Set; | ||||||||||
| 4 | 12 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 12 | ▶ | no warnings 'recursion'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 12 | ▶ | use KiokuDB::Set::Stored; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 12 | ▶ | use KiokuDB::Set::Deferred; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 12 | ▶ | use KiokuDB::Set::Loaded; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 12 | ▶ | use namespace::clean -except => 'meta'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 12 | with qw( | |||||||||
| 15 | KiokuDB::TypeMap::Entry::Std | ||||||||||
| 16 | KiokuDB::TypeMap::Entry::Std::Expand | ||||||||||
| 17 | ); | ||||||||||
| 18 | |||||||||||
| 19 | 12 | has defer => ( | |||||||||
| 20 | isa => "Bool", | ||||||||||
| 21 | is => "ro", | ||||||||||
| 22 | default => 1, | ||||||||||
| 23 | ); | ||||||||||
| 24 | |||||||||||
| 25 | sub compile_collapse_wrapper { | ||||||||||
| 26 | 0 | ▶ | my ( $self, $method, $class, @args ) = @_; | ||||||||
|
Subroutine
compile_collapse_wrapper: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 27 | |||||||||||
| 28 | 0 | my ( $body, @extra ) = $self->compile_collapse_body(@args); | |||||||||
| 29 | |||||||||||
| 30 | return sub { | ||||||||||
| 31 | 0 | ▶ | shift->$method( $body, @extra, @_, class => "KiokuDB::Set::Stored" ); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 32 | } | ||||||||||
| 33 | 0 | } | |||||||||
| 34 | |||||||||||
| 35 | sub compile_collapse_body { | ||||||||||
| 36 | 0 | ▶ | my ( $self, $class ) = @_; | ||||||||
|
Subroutine
compile_collapse_body: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 37 | |||||||||||
| 38 | 0 | ▶ | if ( $class->isa("KiokuDB::Set::Deferred") ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | # if it's deferred we just return the IDs | ||||||||||
| 40 | return sub { | ||||||||||
| 41 | 0 | ▶ | my ( $collapser, %args ) = @_; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 42 | |||||||||||
| 43 | return $collapser->make_entry( | ||||||||||
| 44 | %args, | ||||||||||
| 45 | 0 | data => [ $args{object}->_objects->members ], | |||||||||
| 46 | ); | ||||||||||
| 47 | 0 | }; | |||||||||
| 48 | } else { | ||||||||||
| 49 | # otherwise we collapse the objects recursively | ||||||||||
| 50 | return sub { | ||||||||||
| 51 | 0 | ▶ | my ( $collapser, %args ) = @_; | ||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||
| 52 | |||||||||||
| 53 | 0 | my @inner = $collapser->visit($args{object}->_objects->members); | |||||||||
| 54 | |||||||||||
| 55 | # we flatten references to just IDs | ||||||||||
| 56 | 0 | foreach my $item ( @inner ) { | |||||||||
| 57 | 0 | ▶ | $item = $item->id if ref($item) eq 'KiokuDB::Reference'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 0 | $collapser->_buffer->first_class->insert($item); # mark it first class so it doesn't get compacted | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 0 | return $collapser->make_entry( | |||||||||
| 62 | %args, | ||||||||||
| 63 | data => \@inner, | ||||||||||
| 64 | ); | ||||||||||
| 65 | 0 | }; | |||||||||
| 66 | } | ||||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | sub compile_create { | ||||||||||
| 70 | 0 | ▶ | my ( $self, $class ) = @_; | ||||||||
|
Subroutine
compile_create: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 71 | |||||||||||
| 72 | 0 | ▶ | if ( $self->defer ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | return sub { | ||||||||||
| 74 | 0 | ▶ | my ( $linker, $entry ) = @_; | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 75 | |||||||||||
| 76 | 0 | my $members = $entry->data; | |||||||||
| 77 | |||||||||||
| 78 | 0 | ▶ | if ( grep { ref } @$members ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | 0 | return KiokuDB::Set::Loaded->new( set => Set::Object::Weak->new(), _linker => $linker ); | |||||||||
| 80 | } else { | ||||||||||
| 81 | 0 | return KiokuDB::Set::Deferred->new( set => Set::Object->new( @$members ), _linker => $linker ); | |||||||||
| 82 | } | ||||||||||
| 83 | 0 | }; | |||||||||
| 84 | } else { | ||||||||||
| 85 | return sub { | ||||||||||
| 86 | 0 | ▶ | my ( $linker, $entry ) = @_; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 87 | |||||||||||
| 88 | 0 | return KiokuDB::Set::Loaded->new( set => Set::Object::Weak->new, _linker => $linker ); | |||||||||
| 89 | 0 | }; | |||||||||
| 90 | } | ||||||||||
| 91 | } | ||||||||||
| 92 | |||||||||||
| 93 | sub compile_clear { | ||||||||||
| 94 | 0 | ▶ | my ( $self, $class ) = @_; | ||||||||
|
Subroutine
compile_clear: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 95 | |||||||||||
| 96 | sub { | ||||||||||
| 97 | 0 | ▶ | my ( $linker, $obj ) = @_; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 98 | 0 | $obj->_set_ids( Set::Object->new() ); | |||||||||
| 99 | } | ||||||||||
| 100 | 0 | } | |||||||||
| 101 | |||||||||||
| 102 | sub compile_expand_data { | ||||||||||
| 103 | 0 | ▶ | my ( $self, $class ) = @_; | ||||||||
|
Subroutine
compile_expand_data: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 104 | |||||||||||
| 105 | 0 | my $defer = $self->defer; | |||||||||
| 106 | |||||||||||
| 107 | return sub { | ||||||||||
| 108 | 0 | ▶ | my ( $linker, $instance, $entry ) = @_; | ||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||
| 109 | |||||||||||
| 110 | 0 | my $members = $entry->data; | |||||||||
| 111 | |||||||||||
| 112 | 0 | my $inner_set = $instance->_objects; | |||||||||
| 113 | |||||||||||
| 114 | 0 | ▶ | if ( ref $instance eq 'KiokuDB::Set::Deferred' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 115 | 0 | $inner_set->insert( @$members ); | |||||||||
| 116 | } else { | ||||||||||
| 117 | 0 | foreach my $item ( @$members ) { | |||||||||
| 118 | 0 | ▶ | if ( ref $item ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 119 | 0 | $linker->inflate_data( $item, \( my $obj ) ); | |||||||||
| 120 | 0 | $inner_set->insert( $obj ); | |||||||||
| 121 | } else { | ||||||||||
| 122 | # FIXME add partially loaded set support | ||||||||||
| 123 | 0 | $inner_set->insert( $linker->get_or_load_object($item) ); | |||||||||
| 124 | } | ||||||||||
| 125 | } | ||||||||||
| 126 | } | ||||||||||
| 127 | } | ||||||||||
| 128 | 0 | } | |||||||||
| 129 | |||||||||||
| 130 | 12 | __PACKAGE__->meta->make_immutable; | |||||||||
| 131 | |||||||||||
| 132 | 12 | __PACKAGE__ | |||||||||
| 133 | |||||||||||
| 134 | __END__ | ||||||||||
| 135 | |||||||||||
| 136 | =pod | ||||||||||
| 137 | |||||||||||
| 138 | =head1 NAME | ||||||||||
| 139 | |||||||||||
| 140 | KiokuDB::TypeMap::Entry::Set - A typemap entry for L<KiokuDB::Set>s | ||||||||||
| 141 | |||||||||||
| 142 | =head1 DESCRIPTION | ||||||||||
| 143 | |||||||||||
| 144 | This is an internal typemap entry that handles L<KiokuDB::Set> objects of | ||||||||||
| 145 | various flavours. | ||||||||||
| 146 | |||||||||||
| 147 | You shouldn't need to use it directly, as the default typemap will contain an | ||||||||||
| 148 | entry for it. | ||||||||||