| 1 | package Net::Nostr::Filter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strictures 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Net::Nostr::_ConstructorArgs (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | my @SCALAR_FIELDS = qw(since until limit search); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | my @LIST_FIELDS = qw(ids authors kinds); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | my %HEX64_REQUIRED = map { $_ => 1 } qw(ids authors e p); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | ▶ | sub _validate_hex64 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_hex64: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | my ($field, $values) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | for my $v (@$values) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | croak "$field: '$v' is not 64-char lowercase hex" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | unless $v =~ /\A[0-9a-f]{64}\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | sub _validate_kinds { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_kinds: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | my ($values) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | for my $v (@$values) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | croak "kinds: '$v' is not a valid kind (integer 0-65535)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
defined $v and $v =~ /\A[0-9]+\z/ and $v >= 0 and $v <= 65535
defined $v and $v =~ /\A[0-9]+\z/ and $v >= 0
defined $v and $v =~ /\A[0-9]+\z/
MC/DC0%0/4
defined $v and $v =~ /\A[0-9]+\z/ and $v >= 0 and $v <= 65535
defined $v
$v =~ /\A[0-9]+\z/
$v >= 0
$v <= 65535
Truth table0%0/5
A and B and C and D
A= defined $vB= $v =~ /\A[0-9]+\z/C= $v >= 0D= $v <= 65535
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | unless defined $v && $v =~ /\A[0-9]+\z/ && $v >= 0 && $v <= 65535; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub _validate_non_negative_int { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_non_negative_int: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | my ($field, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | croak "$field must be a non-negative integer" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $value and $value =~ /\A[0-9]+\z/
MC/DC0%0/2
defined $value and $value =~ /\A[0-9]+\z/
defined $value
$value =~ /\A[0-9]+\z/
Truth table0%0/3
A and B
A= defined $valueB= $value =~ /\A[0-9]+\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | unless defined $value && $value =~ /\A[0-9]+\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | ▶ | use Class::Tiny qw(since until limit search _tag_filters); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # Read-only accessors for list fields that return shallow copies. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | for my $field (@LIST_FIELDS) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 2 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | *$field = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | croak "$field is read-only" if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | return defined $self->{$field} ? [@{$self->{$field}}] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 6 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=25 SCAR=64.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my %args = Net::Nostr::_ConstructorArgs::normalize(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | my %known = map { $_ => 1 } (@SCALAR_FIELDS, @LIST_FIELDS); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | my @unknown = grep { !$known{$_} && !/\A#[a-zA-Z][a-zA-Z0-9_]*\z/ } keys %args; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$known{$_} || /\A#[a-zA-Z][a-zA-Z0-9_]*\z/
MC/DC0%0/2
$known{$_} || /\A#[a-zA-Z][a-zA-Z0-9_]*\z/
$known{$_}
/\A#[a-zA-Z][a-zA-Z0-9_]*\z/
Truth table0%0/3
A || B
A= $known{$_}B= /\A#[a-zA-Z][a-zA-Z0-9_]*\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | croak "unknown argument(s): " . join(', ', sort @unknown) if @unknown; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | for my $f (@SCALAR_FIELDS) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if (exists $args{$f}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | _validate_non_negative_int($f, $args{$f}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$f eq "since" or $f eq "until" or $f eq "limit"
$f eq "since" or $f eq "until"
MC/DC0%0/3
$f eq "since" or $f eq "until" or $f eq "limit"
$f eq "since"
$f eq "until"
$f eq "limit"
Truth table0%0/4
A or B or C
A= $f eq "since"B= $f eq "until"C= $f eq "limit"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | if $f eq 'since' || $f eq 'until' || $f eq 'limit'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | croak "search must be a string" if $f eq 'search' && ref($args{$f}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$f eq "search" and ref $args{$f}
MC/DC0%0/2
$f eq "search" and ref $args{$f}
$f eq "search"
ref $args{$f}
Truth table0%0/3
A and B
A= $f eq "search"B= ref $args{$f}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $self->$f($args{$f}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # Pre-parse and lowercase search terms for O(1) matching | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ($f eq 'search' && defined $args{$f} && length $args{$f}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$f eq "search" and defined $args{$f} and length $args{$f}
$f eq "search" and defined $args{$f}
MC/DC0%0/3
$f eq "search" and defined $args{$f} and length $args{$f}
$f eq "search"
defined $args{$f}
length $args{$f}
Truth table0%0/4
A and B and C
A= $f eq "search"B= defined $args{$f}C= length $args{$f}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my $parsed = $self->parse_search_extensions($args{$f}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $self->{_search_terms} = [map { lc($_) } @{$parsed->{terms}}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | for my $f (@LIST_FIELDS) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if (exists $args{$f}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | croak "$f must be a non-empty array" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | unless ref($args{$f}) eq 'ARRAY' && @{$args{$f}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $args{$f} eq "ARRAY" and @{$args{$f};}
MC/DC0%0/2
ref $args{$f} eq "ARRAY" and @{$args{$f};}
ref $args{$f} eq "ARRAY"
@{$args{$f};}
Truth table0%0/3
A and B
A= ref $args{$f} eq "ARRAY"B= @{$args{$f};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | _validate_hex64($f, $args{$f}) if $HEX64_REQUIRED{$f}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | _validate_kinds($args{$f}) if $f eq 'kinds'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | $self->{$f} = [@{$args{$f}}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # Pre-build hash set for O(1) matching | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | $self->{"_${f}_set"} = { map { $_ => 1 } @{$args{$f}} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # extract #<tag-name> tag filters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my %tf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | for my $k (keys %args) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if ($k =~ /\A#([a-zA-Z][a-zA-Z0-9_]*)\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | croak "$k must be a non-empty array" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | unless ref($args{$k}) eq 'ARRAY' && @{$args{$k}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $args{$k} eq "ARRAY" and @{$args{$k};}
MC/DC0%0/2
ref $args{$k} eq "ARRAY" and @{$args{$k};}
ref $args{$k} eq "ARRAY"
@{$args{$k};}
Truth table0%0/3
A and B
A= ref $args{$k} eq "ARRAY"B= @{$args{$k};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | _validate_hex64("#$1", $args{$k}) if $HEX64_REQUIRED{$1}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $tf{$1} = [@{$args{$k}}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | $self->_tag_filters(\%tf) if %tf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub tag_filter { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tag_filter: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my ($self, $letter) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my $tf = $self->_tag_filters; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | return ($tf && $tf->{$letter}) ? [@{$tf->{$letter}}] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$tf and $tf->{$letter}
MC/DC0%0/2
$tf and $tf->{$letter}
$tf
$tf->{$letter}
Truth table0%0/3
A and B
A= $tfB= $tf->{$letter}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | sub matches { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
matches: not called CC=23 SCAR=63.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | my ($self, $event) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if ($self->{_ids_set}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | return 0 unless $self->{_ids_set}{$event->id}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if ($self->{_authors_set}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | return 0 unless $self->{_authors_set}{$event->pubkey}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | if ($self->{_kinds_set}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | return 0 unless $self->{_kinds_set}{$event->kind}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | if (defined $self->{since}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | return 0 unless $event->created_at >= $self->{since}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if (defined $self->{until}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | return 0 unless $event->created_at <= $self->{until}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | if ($self->{_search_terms} && @{$self->{_search_terms}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"_search_terms"} and @{$self->{"_search_terms"};}
MC/DC0%0/2
$self->{"_search_terms"} and @{$self->{"_search_terms"};}
$self->{"_search_terms"}
@{$self->{"_search_terms"};}
Truth table0%0/3
A and B
A= $self->{"_search_terms"}B= @{$self->{"_search_terms"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | my $content = lc($event->content // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$event->content // ""
MC/DC0%0/1
$event->content // ""
$event->content
Truth table0%0/2
A
A= $event->content
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | for my $term (@{$self->{_search_terms}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | return 0 unless index($content, $term) >= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | if ($self->{_tag_filters}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | for my $letter (keys %{ $self->{_tag_filters} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | my $filter_values = $self->{_tag_filters}{$letter}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # Build hash set of event's tag values for this letter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my %event_vals; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | for my $tag (@{ $event->_tags }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | $event_vals{$tag->[1]} = 1 if $tag->[0] eq $letter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | my $found = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | for my $fv (@$filter_values) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | if ($event_vals{$fv}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $found = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | return 0 unless $found; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | sub matches_any { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
matches_any: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | my ($class, $event, @filters) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | for my $f (@filters) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | return 1 if $f->matches($event); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | sub parse_search_extensions { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_search_extensions: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | my ($class, $search_str) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | my (@terms, %extensions); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | return { terms => \@terms, extensions => \%extensions } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $search_str and length $search_str
MC/DC0%0/2
defined $search_str and length $search_str
defined $search_str
length $search_str
Truth table0%0/3
A and B
A= defined $search_strB= length $search_str
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | unless defined $search_str && length $search_str; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | for my $word (split /\s+/, $search_str) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | next unless length $word; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | if ($word =~ /^([a-zA-Z_]+):(.+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | $extensions{$1} = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | push @terms, $word; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | return { terms => \@terms, extensions => \%extensions }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | sub to_hash { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_hash: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | my %h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | for my $f (@LIST_FIELDS) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | $h{$f} = [@{$self->{$f}}] if defined $self->{$f}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | for my $f (@SCALAR_FIELDS) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | my $val = $self->$f; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | $h{$f} = $val if defined $val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | if ($self->_tag_filters) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | for my $letter (keys %{ $self->_tag_filters }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | $h{"#$letter"} = [@{$self->_tag_filters->{$letter}}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | return \%h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||