blib/lib/OPTIMADE/Filter/Property.pm

filter: Statementstmt 96.5% 56 / 58 Branchbran 62.5% 15 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 93.3% 14 / 15 Podpod 0.0% 0 / 5 totaltotal 83.3% 85 / 102 CC 15 SCAR 14.7
CC
15
Cov
87%
_eq
9.5
to_SQL
5.1
to_filter
3.0
CRAP 4.4
« lib/OPTIMADE/Filter/Parser.yp ↑ Summary blib/lib/OPTIMADE/Filter/Zip.pm »
1 package OPTIMADE::Filter::Property;
2  
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 ▶use parent 'OPTIMADE::Filter::Modifiable';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 7 our $VERSION = '0.11.0'; # VERSION
10  
11 2768 ▶use overload '@{}' => sub { return $_[0]->{name} },
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
12 555 ▶ '""' => sub { return $_[0]->to_filter },
Subroutine __ANON__: called CC=1 SCAR=0.0
13 0 ▶ '==' => sub { return $_[0]->_eq( $_[1] ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
14 7 ▶ 'eq' => sub { return $_[0]->_eq( $_[1] ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
15  
16 7 our $identifier_re = q/([a-z_][a-z0-9_]*)/;
17  
18 272 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
19 272 my $class = shift;
20 272 return bless { name => \@_ }, $class;
21 }
22  
23 sub to_filter
24 817 ▶{
Subroutine to_filter: called CC=3 SCAR=11.0
Pod undocumented
25 817 my( $self ) = @_;
26  
27 # Validate
28 817 $self->validate;
29 817 for my $name (@$self) {
30 826 my $lc_name = lc $name;
31 826 ▶ next if $lc_name =~ /^$identifier_re$/;
Branch: 1 branch
BranchTrueFalseTotal
if $lc_name =~ /^$OPTIMADE::Filter::Property::identifier_re$/ 825 1 826
32 1 die "name '$lc_name' does not match identifier syntax: $identifier_re";
33 }
34  
35 816 return join '.', map { lc } @$self;
36 }
37  
38 sub to_SQL
39 100 ▶{
Subroutine to_SQL: called CC=5 SCAR=16.3
Pod undocumented
40 100 my( $self, $options ) = @_;
41  
42 100 ▶ $options = {} unless $options;
Branch: 1 branch
BranchTrueFalseTotal
unless $options 1 99 100
43 my( $delim, $placeholder ) = (
44 $options->{delim},
45 $options->{placeholder},
46 100 );
47 100 ▶ $delim = "'" unless $delim;
Branch: 1 branch
BranchTrueFalseTotal
unless $delim 100 0 100
48  
49 # Validate
50 100 $self->validate;
51 100 ▶ if( @$self > 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$self > 2) 0 100 100
52 0 die 'no SQL representation for properties of more than two ' .
53 "identifiers\n";
54 }
55  
56 # Construct the SQL
57 100 my $sql = join '.', map { "${delim}$_${delim}" } @$self;
58  
59 100 ▶ if( wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 99 1 100
60 99 return ( $sql, [] );
61 } else {
62 1 return $sql;
63 }
64 }
65  
66 sub modify
67 7 ▶{
Subroutine modify: called CC=1 SCAR=0.0
Pod undocumented
68 7 my $self = shift;
69 7 my $code = shift;
70  
71 7 return $code->( $self, @_ );
72 }
73  
74 sub validate
75 917 ▶{
Subroutine validate: called CC=2 SCAR=7.2
Pod undocumented
76 917 my $self = shift;
77 917 ▶ die 'name undefined for OPTIMADE::Filter::Property' if !@$self;
Branch: 1 branch
BranchTrueFalseTotal
if not @$self 0 917 917
78 }
79  
80 sub _eq
81 1 ▶{
Subroutine _eq: called CC=8 SCAR=22.5
82 1 my( $a, $b ) = @_;
83  
84 1 ▶ return '' if !blessed( $b );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($b) 0 1 1
85 1 ▶ return '' if !$b->isa( OPTIMADE::Filter::Property:: );
Branch: 1 branch
BranchTrueFalseTotal
unless $b->isa("OPTIMADE::Filter::Property") 0 1 1
86  
87 1 ▶ return '' if @$a != @$b;
Branch: 1 branch
BranchTrueFalseTotal
if @$a != @$b 0 1 1
88 1 for my $i (0..$#$a) {
89 2 ▶ return '' if defined $a->[$i] ^ defined $b->[$i];
Branch: 1 branch
BranchTrueFalseTotal
if defined $a->[$i] ^ defined $b->[$i] 0 2 2
90 2 ▶ next if !defined $a->[$i];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $a->[$i] 0 2 2
91 2 ▶ return '' if $a->[$i] ne $b->[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $a->[$i] ne $b->[$i] 0 2 2
92 }
93 1 return 1;
94 }
95  
96 7 1;
« lib/OPTIMADE/Filter/Parser.yp ↑ Summary blib/lib/OPTIMADE/Filter/Zip.pm »