blib/lib/Langertha.pm

filter: Statementstmt 87.8% 94 / 107 Branchbran 70.0% 21 / 30 Conditioncond 30.0% 6 / 20 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 85.0% 17 / 20 Podpod 80.0% 4 / 5 totaltotal 73.2% 142 / 194 CC 26 SCAR 15.1
CC
26
Cov
77%
resolve_engine_class
8.2
discover_modules_in_scope
6.3
import
6.0
CRAP 4.5
« blib/lib/Langertha/Engine/Groq.pm ↑ Summary blib/lib/Langertha/Engine/HuggingFace.pm »
1 package Langertha;
2 # ABSTRACT: The clan of fierce vikings with axes and shields to AId your rAId
3 5 our $VERSION = '0.505';
4 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Import::Into;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Module::Pluggable::Object ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Module::Runtime qw( require_module use_module );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 5 my %_sugar_plugins; # per-class plugin accumulator
14  
15 my %setup = (
16 0 ▶ Raider => sub {
Subroutine __ANON__: not called CC=1 SCAR=4.4
17 0 my ( $caller ) = @_;
18 0 Moose->import::into($caller);
19 0 Future::AsyncAwait->import::into($caller);
20 0 $caller->meta->superclasses('Langertha::Raider');
21 0 $_sugar_plugins{$caller} = [];
22 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 0 ▶ *{"${caller}::plugin"} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 0 push @{$_sugar_plugins{$caller}}, @_;
25 0 };
26 0 ▶ $caller->meta->add_method('_sugar_plugins' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
27 0 ▶ return [@{$_sugar_plugins{$caller} // []}];
Condition0%0/2
$_sugar_plugins{$caller} // []
l!l
00
MC/DC0%0/1
$_sugar_plugins{$caller} // []
$_sugar_plugins{$caller}
Truth table0%0/2
A
A= $_sugar_plugins{$caller}
Aresult
11
00
28 0 });
29 },
30 1 ▶ Plugin => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
31 1 my ( $caller ) = @_;
32 1 Moose->import::into($caller);
33 1 Future::AsyncAwait->import::into($caller);
34 1 $caller->meta->superclasses('Langertha::Plugin');
35 },
36 5 );
37  
38 4 ▶sub import {
Subroutine import: called CC=6 SCAR=18.0
39 4 my ( $class, @args ) = @_;
40 4 ▶ return unless @args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 2 2 4
41 2 my $caller = caller;
42 2 for my $arg (@args) {
43 2 ▶ my $setup = $setup{$arg}
Branch: 1 branch
BranchTrueFalseTotal
my $setup = $setup{$arg} or Carp::croak("Unknown Langertha import '${arg}' (known: " . join(", ", sort(keys %setup)) . ')') 1 1 2
44 or Carp::croak("Unknown Langertha import '$arg' (known: ".join(', ', sort keys %setup).")");
45 1 require Moose;
46 1 require Future::AsyncAwait;
47 1 ▶ use_module('Langertha::Raider') if $arg eq 'Raider';
Branch: 1 branch
BranchTrueFalseTotal
if $arg eq "Raider" 0 1 1
48 1 ▶ use_module('Langertha::Plugin') if $arg eq 'Plugin';
Branch: 1 branch
BranchTrueFalseTotal
if $arg eq "Plugin" 1 0 1
49 1 $setup->($caller);
50 }
51 }
52  
53 2 ▶sub _module_path {
Subroutine _module_path: called CC=1 SCAR=0.0
54 2 my ($module) = @_;
55 2 my $path = $module;
56 2 $path =~ s{::}{/}g;
57 2 return $path . '.pm';
58 }
59  
60 2 ▶sub _is_missing_module_error {
Subroutine _is_missing_module_error: called CC=4 SCAR=15.6
61 2 my ($err, $module) = @_;
62 2 ▶ return 0 unless defined $err && length $err;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $err and length $err 0 2 2
Condition33%1/3
defined $err and length $err
!ll&&!rl&&r
002
MC/DC0%0/2
defined $err and length $err
defined $err length $err
Truth table33%1/3
A and B
A= defined $errB= length $err
ABresult
0X0
100
111
63 2 my $pm_path = _module_path($module);
64 2 ▶ return index($err, "Can't locate $pm_path in \@INC") >= 0 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
index($err, "Can't locate $pm_path in \@INC") != -1 ? : 2 0 2
65 }
66  
67 12 ▶sub discover_modules_in_scope {
Subroutine discover_modules_in_scope: called CC=5 SCAR=18.3
Pod undocumented
68 12 my ($class, %args) = @_;
69 12 my $search_path = $args{search_path};
70 12 ▶ $search_path = ['Langertha::Engine', 'LangerthaX::Engine']
Branch: 1 branch
BranchTrueFalseTotal
unless ref $search_path eq "ARRAY" and @$search_path 0 12 12
Condition33%1/3
ref $search_path eq "ARRAY" and @$search_path
!ll&&!rl&&r
0012
MC/DC0%0/2
ref $search_path eq "ARRAY" and @$search_path
ref $search_path eq "ARRAY" @$search_path
Truth table33%1/3
A and B
A= ref $search_path eq "ARRAY"B= @$search_path
ABresult
0X0
100
111
71 unless ref($search_path) eq 'ARRAY' && @$search_path;
72  
73 12 my $finder = Module::Pluggable::Object->new(
74 search_path => $search_path,
75 require => 0,
76 inner => 0,
77 );
78  
79 12 my %seen;
80 12 ▶ my @modules = grep { defined $_ && length $_ && !$seen{$_}++ } $finder->plugins;
Condition33%2/6
defined $_ && length $_ && !$seen{$_}++
!ll&&!rl&&r
00487
defined $_ and length $_
!ll&&!rl&&r
00487
MC/DC0%0/3
defined $_ && length $_ && !$seen{$_}++
defined $_ length $_ !$seen{$_}++
Truth table25%1/4
A and B && not(C)
A= defined $_B= length $_C= !$seen{$_}++
ABCresult
0XX0
10X0
1100
1111
81 12 return [ sort @modules ];
82 }
83  
84 12 ▶sub available_engine_classes {
Subroutine available_engine_classes: called CC=1 SCAR=0.0
Pod documented
85 12 my ($class) = @_;
86 12 return $class->discover_modules_in_scope(
87 search_path => ['Langertha::Engine', 'LangerthaX::Engine'],
88 );
89 }
90  
91 3 ▶sub available_engine_ids {
Subroutine available_engine_ids: called CC=3 SCAR=11.0
Pod documented
92 3 my ($class) = @_;
93 3 my %ids;
94 3 for my $module (@{$class->available_engine_classes}) {
95 121 ▶ next unless $module =~ /::([^:]+)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $module =~ /::([^:]+)\z/ 0 121 121
96 121 $ids{lc($1)} = 1;
97 }
98 3 return [ sort keys %ids ];
99 }
100  
101 9 ▶sub resolve_engine_class {
Subroutine resolve_engine_class: called CC=8 SCAR=21.0
Pod documented
102 9 my ($class, $engine) = @_;
103 9 ▶ Carp::croak("No engine specified") unless defined($engine) && length($engine);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $engine and length $engine 0 9 9
Condition33%1/3
defined $engine and length $engine
!ll&&!rl&&r
009
MC/DC0%0/2
defined $engine and length $engine
defined $engine length $engine
Truth table33%1/3
A and B
A= defined $engineB= length $engine
ABresult
0X0
100
111
104  
105 9 my @candidates;
106 9 ▶ if ($engine =~ /::/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($engine =~ /::/) { } 1 8 9
107 1 @candidates = ($engine);
108 } else {
109 8 my @ordered = ("Langertha::Engine::$engine", "LangerthaX::Engine::$engine");
110 8 my %available = map { $_ => 1 } @{$class->available_engine_classes};
111 8 @candidates = grep { $available{$_} } @ordered;
112 8 ▶ @candidates = @ordered unless @candidates;
Branch: 1 branch
BranchTrueFalseTotal
unless @candidates 1 7 8
113 }
114  
115 9 my @errors;
116 9 for my $candidate (@candidates) {
117 10 my $ok = eval {
118 10 require_module($candidate);
119 8 1;
120 };
121 10 ▶ return $candidate if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 8 2 10
122 2 my $err = $@;
123 2 ▶ if (!_is_missing_module_error($err, $candidate)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_is_missing_module_error($err, $candidate)) 0 2 2
124 0 Carp::croak($err);
125 }
126 2 push @errors, $candidate;
127 }
128  
129 Carp::croak(
130 1 "Engine '$engine' not found (tried: " . join(', ', @errors) . ")"
131 );
132 }
133  
134 4 ▶sub new_engine {
Subroutine new_engine: called CC=4 SCAR=14.5
Pod documented
135 4 my ($class, $engine, @args) = @_;
136 4 ▶ Carp::croak("No engine specified") unless defined($engine) && length($engine);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $engine and length $engine 0 4 4
Condition33%1/3
defined $engine and length $engine
!ll&&!rl&&r
004
MC/DC0%0/2
defined $engine and length $engine
defined $engine length $engine
Truth table33%1/3
A and B
A= defined $engineB= length $engine
ABresult
0X0
100
111
137 4 ▶ Carp::croak("Engine constructor arguments must be key/value pairs")
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 1 3 4
138 if @args % 2;
139  
140 3 my $engine_class = $class->resolve_engine_class($engine);
141 3 return $engine_class->new(@args);
142 }
143  
144  
145 5 1;
146  
147 __END__
« blib/lib/Langertha/Engine/Groq.pm ↑ Summary blib/lib/Langertha/Engine/HuggingFace.pm »