File Coverage

blib/lib/Search/GIN/Extract/Attributes.pm
Criterion Covered Total %
statement 22 26 84.6
branch 2 4 50.0
condition n/a
subroutine 6 6 100.0
pod 0 2 0.0
total 30 38 78.9


line stmt bran cond sub pod time code
1 1     1   1222 use strict;
  1         2  
  1         39  
2 1     1   4 use warnings;
  1         2  
  1         51  
3             package Search::GIN::Extract::Attributes;
4              
5             our $VERSION = '0.11';
6              
7 1     1   4 use Moose;
  1         1  
  1         7  
8 1     1   5418 use namespace::autoclean;
  1         2  
  1         8  
9              
10             with qw(
11             Search::GIN::Extract
12             Search::GIN::Keys::Deep
13             );
14              
15             has attributes => (
16             isa => "ArrayRef[Str]",
17             is => "rw",
18             predicate => "has_attributes",
19             );
20              
21             sub extract_values {
22 3     3 0 7 my ( $self, $obj, @args ) = @_;
23              
24 3         9 my @meta_attrs = $self->get_meta_attrs($obj, @args);
25              
26 6         19 return $self->process_keys({ map {
27 3         78 my $val = $_->get_value($obj);
28 6 50       682 $_->name => (defined($val) ? $val : undef);
29             } @meta_attrs });
30             }
31              
32             sub get_meta_attrs {
33 3     3 0 3 my ( $self, $obj, @args ) = @_;
34              
35 3         5 my $class = ref $obj;
36 3         8 my $meta = Class::MOP::get_metaclass_by_name($class);
37              
38 3 50       105 if ( $self->has_attributes ) {
39 0         0 return grep { defined } map { $meta->find_attribute_by_name($_) } @{ $self->attributes };
  0         0  
  0         0  
  0         0  
40             } else {
41 3         11 return $meta->get_all_attributes;
42             }
43             }
44              
45             __PACKAGE__->meta->make_immutable;
46              
47             1;