| 1 | package Net::Async::WebSearch::Provider; | ||||||||||||||||||||||||||||
| 2 | 6 | our $VERSION = '0.002'; | |||||||||||||||||||||||||||
| 3 | # ABSTRACT: Base class for Net::Async::WebSearch providers | ||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | sub new { | ||||||||||||||||||||||||||||
| 9 | 33 | ▶ | my ( $class, %args ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 10 | 33 | my $self = bless { %args }, $class; | |||||||||||||||||||||||||||
| 11 | 33 | ▶ | $self->{enabled} = 1 unless defined $self->{enabled}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 12 | 33 | ▶ | $self->{tags} ||= []; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"tags"} ||= []
MC/DC100%1/1
$self->{"tags"} ||= []
$self->{"tags"}
Truth table100%2/2
A
A= $self->{"tags"}
| |||||||||||||||||||||||||||||
| 13 | 33 | $self->_init; | |||||||||||||||||||||||||||
| 14 | 30 | return $self; | |||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | ▶ | sub _init {} | |||||||||||||||||||||||||||
|
Subroutine
_init: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | sub default_name { | ||||||||||||||||||||||||||||
| 20 | 13 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
default_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | 13 | my $pkg = ref $self; | |||||||||||||||||||||||||||
| 22 | 13 | $pkg =~ s/.*:://; | |||||||||||||||||||||||||||
| 23 | 13 | return lc $pkg; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | sub name { | ||||||||||||||||||||||||||||
| 27 | 273 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
name: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | 273 | ▶ | @_ > 1 ? ($self->{name} = $_[1]) : ($self->{name} // $self->default_name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"name"} // $self->default_name
MC/DC0%0/2
$self->{"name"} // $self->default_name
$self->{"name"}
$self->default_name
Truth table66%2/3
A // B
A= $self->{"name"}B= $self->default_name
| |||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 66 | ▶ | sub enabled { @_ > 1 ? ($_[0]->{enabled} = $_[1]) : $_[0]->{enabled} } | ||||||||||||||||||||||||||
|
Subroutine
enabled: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | sub tags { | ||||||||||||||||||||||||||||
| 34 | 0 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
tags: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | return @{ $self->{tags} || [] }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | sub has_tag { | ||||||||||||||||||||||||||||
| 39 | 47 | ▶ | my ( $self, $tag ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
has_tag: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 47 | ▶ | return scalar grep { $_ eq $tag } @{ $self->{tags} || [] }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | sub matches { | ||||||||||||||||||||||||||||
| 44 | 72 | ▶ | my ( $self, $sel ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
matches: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 72 | ▶ | return 1 if $sel eq $self->name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 51 | ▶ | return 1 if $sel eq $self->default_name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 47 | ▶ | return 1 if $self->has_tag($sel); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 36 | return 0; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | sub user_agent_string { | ||||||||||||||||||||||||||||
| 52 | 17 | ▶ | 'Net-Async-WebSearch/' . ($Net::Async::WebSearch::VERSION // 'dev'); | ||||||||||||||||||||||||||
|
Subroutine
user_agent_string: called CC=2 SCAR=7.6
Pod
documented
Condition50%1/2
$Net::Async::WebSearch::VERSION // "dev"
MC/DC0%0/1
$Net::Async::WebSearch::VERSION // "dev"
$Net::Async::WebSearch::VERSION
Truth table50%1/2
A
A= $Net::Async::WebSearch::VERSION
| |||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | # Subclasses MUST implement. | ||||||||||||||||||||||||||||
| 56 | # Signature: $self->search($http, $query, \%opts) | ||||||||||||||||||||||||||||
| 57 | # Returns: Future of arrayref of Net::Async::WebSearch::Result | ||||||||||||||||||||||||||||
| 58 | sub search { | ||||||||||||||||||||||||||||
| 59 | 0 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
search: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 0 | croak ref($self).": must implement search()"; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 6 | 1; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | __END__ | ||||||||||||||||||||||||||||