GIN/Query/Attributes.pm

filter: Statementstmt 92.8% 39 / 42 Branchbran 50.0% 2 / 4 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 4 totaltotal 80.6% 50 / 62 CC 6 SCAR 8.8
CC
6
Cov
88%
compare_naive
4.2
consistent
3.0
compare_test_deep
2.0
CRAP 2.4
« GIN/Driver/Hash.pm ↑ Summary GIN.pm »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Search::GIN::Query::Attributes;
4 # ABSTRACT: Create attributes-based GIN queries
5  
6 1 our $VERSION = '0.11';
7  
8 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 with qw(
13 Search::GIN::Query
14 Search::GIN::Keys::Deep
15 );
16  
17 1 has attributes => (
18 isa => "HashRef",
19 is => "rw",
20 required => 1,
21 );
22  
23 1 has compare => (
24 isa => "Str|CodeRef",
25 is => "rw",
26 default => "compare_naive",
27 );
28  
29 3 ▶sub extract_values {
Subroutine extract_values: called CC=1 SCAR=0.0
Pod undocumented
30 3 my $self = shift;
31  
32 return (
33 3 method => "all",
34 values => [ $self->process_keys($self->attributes) ],
35 );
36 }
37  
38 3 ▶sub consistent {
Subroutine consistent: called CC=3 SCAR=11.0
Pod undocumented
39 3 my ( $self, $index, $obj ) = @_;
40  
41 3 my $class = ref $obj;
42  
43 3 my $meta = Class::MOP::get_metaclass_by_name($class);
44  
45 3 my $query = $self->attributes;
46  
47 3 my %got;
48  
49 3 foreach my $attr_name ( keys %$query ) {
50 3 my $expected = $query->{$attr_name};
51  
52 3 ▶ my $meta_attr = $meta->find_attribute_by_name($attr_name) || return;
Condition50%1/2
$meta->find_attribute_by_name($attr_name) || (return)
l!l
30
MC/DC0%0/1
$meta->find_attribute_by_name($attr_name) || (return)
$meta->find_attribute_by_name($attr_name)
Truth table50%1/2
A
A= $meta->find_attribute_by_name($attr_name)
Aresult
11
00
53 3 $got{$attr_name} = $meta_attr->get_value($obj);
54 }
55  
56 3 my $cmp = $self->compare;
57  
58 3 return $self->$cmp( \%got, $query );
59 }
60  
61 3 ▶sub compare_naive {
Subroutine compare_naive: called CC=4 SCAR=14.3
Pod undocumented
62 3 my ( $self, $got, $exp ) = @_;
63  
64 3 ▶ return unless keys %$got == keys %$exp;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$got == keys %$exp 0 3 3
65  
66 3 foreach my $key ( keys %$exp ) {
67 3 ▶ return unless overload::StrVal($got->{$key}) eq overload::StrVal($exp->{$key});
Branch: 1 branch
BranchTrueFalseTotal
unless overload::StrVal($got->{$key}) eq overload::StrVal($exp->{$key}) 0 3 3
68 }
69  
70 3 return 1;
71 }
72  
73 0 ▶sub compare_test_deep {
Subroutine compare_test_deep: not called CC=1 SCAR=6.9
Pod undocumented
74 0 my ( $self, $got, $exp ) = @_;
75  
76 0 require Test::Deep::NoTest;
77 0 Test::Deep::NoTest::eq_deeply($got, $exp);
78 }
79  
80 # FIXME Data::Compare too
81  
82 1 __PACKAGE__->meta->make_immutable;
83  
84 1 1;
85  
86 __END__
« GIN/Driver/Hash.pm ↑ Summary GIN.pm »