lib/App/ElasticSearch/Utilities/QueryString/IP.pm

filter: Statementstmt 100% 26 / 26 Branchbran 75.0% 3 / 4 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 90.7% 39 / 43 CC 4 SCAR 8.0
CC
4
Cov
94%
handle_token
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.2
« lib/Types/ElasticSearch.pm ↑ Summary lib/App/ElasticSearch/Utilities/QueryString/Underscored.pm »
1 package App::ElasticSearch::Utilities::QueryString::IP;
2 # ABSTRACT: Expand IP CIDR Notation to ES ranges
3  
4 2 ▶use v5.16;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = '9.1'; # VERSION
8  
9 2 ▶use Net::CIDR::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 with 'App::ElasticSearch::Utilities::QueryString::Plugin';
14  
15 1 ▶sub _build_priority { 25 }
Subroutine _build_priority: called CC=1 SCAR=0.0
16  
17  
18 5 ▶sub handle_token {
Subroutine handle_token: called CC=4 SCAR=14.0
Pod undocumented
19 5 my ($self,$token) = @_;
20 5 ▶ if( my ($term,$match) = split /\:/, $token, 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = split(/\:/u, $token, 2)) 5 0 5
21 # These are not 100% accurate IP matchers, but they are fast
22 5 ▶ if( $match =~ m|^\d{1,3}(?:\.\d{1,3}){1,3}(?:/\d+)$|
Branch: 1 branch
BranchTrueFalseTotal
if ($match =~ m[^\d{1,3}(?:\.\d{1,3}){1,3}(?:/\d+)$]u or $match =~ m[^[0-9a-fA-F:]+(?:/\d+)$]u) 1 4 5
Condition66%2/3
$match =~ m[^\d{1,3}(?:\.\d{1,3}){1,3}(?:/\d+)$]u or $match =~ m[^[0-9a-fA-F:]+(?:/\d+)$]u
l!l&&r!l&&!r
104
MC/DC50%1/2
$match =~ m[^\d{1,3}(?:\.\d{1,3}){1,3}(?:/\d+)$]u or $match =~ m[^[0-9a-fA-F:]+(?:/\d+)$]u
$match =~ m[^\d{1,3}(?:\.\d{1,3}){1,3}(?:/\d+)$]u $match =~ m[^[0-9a-fA-F:]+(?:/\d+)$]u
Truth table66%2/3
A or B
A= $match =~ m[^\d{1,3}(?:\.\d{1,3}){1,3}(?:/\d+)$]uB= $match =~ m[^[0-9a-fA-F:]+(?:/\d+)$]u
ABresult
1X1
011
000
23 or $match =~ m|^[0-9a-fA-F:]+(?:/\d+)$|
24 ) {
25 1 my $cidr = Net::CIDR::Lite->new();
26 1 $cidr->add($match);
27 1 my @range = split /-/, ($cidr->list_range)[0];
28 1 return { condition => { range => { $term => { gte => $range[0], lte => $range[1] } } } };
29 }
30 }
31 4 return;
32 }
33  
34 1 1;
35  
36 __END__
« lib/Types/ElasticSearch.pm ↑ Summary lib/App/ElasticSearch/Utilities/QueryString/Underscored.pm »