| 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
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$match =~ m[^\d{1,3}(?:\.\d{1,3}){1,3}(?:/\d+)$]u or $match =~ m[^[0-9a-fA-F:]+(?:/\d+)$]u
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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||