Chrome/DevToolsProtocol/Transport.pm

filter: Statementstmt 90.3% 28 / 31 Branchbran 50.0% 3 / 6 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 5 / 5 Podpod 50.0% 1 / 2 totaltotal 77.5% 38 / 49 CC 6 SCAR 12.9
CC
6
Cov
80%
best_implementation
5.8
new
2.1
BEGIN
1.0
CRAP 3.6
« Chrome/DevToolsProtocol/Transport/NetAsync.pm ↑ Summary Chrome/DevToolsProtocol/Transport/Pipe/Mojo.pm »
1 package Chrome::DevToolsProtocol::Transport;
2 70 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 70 ▶no warnings 'experimental::signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 70 ▶use feature 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 70 our $VERSION = '0.80';
7  
8 =head1 NAME
9  
10 Chrome::DevToolsProtocol::Transport - choose the best transport backend
11  
12 =cut
13  
14 70 our @loops;
15 70 push @loops, (
16 ['Mojo/IOLoop.pm' => 'Chrome::DevToolsProtocol::Transport::Mojo' ],
17 ['IO/Async.pm' => 'Chrome::DevToolsProtocol::Transport::NetAsync'],
18 ['IO/Async/Loop.pm' => 'Chrome::DevToolsProtocol::Transport::NetAsync'],
19 ['AnyEvent.pm' => 'Chrome::DevToolsProtocol::Transport::AnyEvent'],
20 ['AE.pm' => 'Chrome::DevToolsProtocol::Transport::AnyEvent'],
21 # native POE support would be nice
22 );
23 70 our $implementation;
24 70 our $default = 'Chrome::DevToolsProtocol::Transport::NetAsync';
25  
26 =head1 METHODS
27  
28 =head2 C<< Chrome::DevToolsProtocol::Transport->new() >>
29  
30 my $ua = Chrome::DevToolsProtocol::Transport->new();
31  
32 Creates a new instance of the transport using the "best" event loop
33 for implementation. The default event loop is currently L<AnyEvent>.
34  
35 All parameters are passed on to the implementation class.
36  
37 =cut
38  
39 1 ▶sub new($factoryclass, @args) {
Subroutine new: called CC=2 SCAR=7.6
Pod documented
40 1 ▶ $implementation ||= $factoryclass->best_implementation();
Condition33%1/3
$Chrome::DevToolsProtocol::Transport::implementation ||= $factoryclass->best_implementation
l!l&&r!l&&!r
010
MC/DC0%0/2
$Chrome::DevToolsProtocol::Transport::implementation ||= $factoryclass->best_implementation
$Chrome::DevToolsProtocol::Transport::implementation $factoryclass->best_implementation
Truth table33%1/3
A ||= B
A= $Chrome::DevToolsProtocol::Transport::implementationB= $factoryclass->best_implementation
ABresult
1X1
011
000
41  
42 # Just in case a user has set this from the outside
43 1 eval "require $implementation; 1";
44  
45 # return a new instance
46 1 $implementation->new(@args);
47 }
48  
49 1 ▶sub best_implementation( $class, @candidates ) {
Subroutine best_implementation: called CC=5 SCAR=17.6
Pod undocumented
50  
51 1 ▶ if(! @candidates) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@candidates) 1 0 1
52 1 @candidates = @loops;
53 };
54  
55 # Find the currently running/loaded event loop(s)
56 #use Data::Dumper;
57 #warn Dumper \%INC;
58 #warn Dumper \@candidates;
59 my @applicable_implementations = map {
60 0 $_->[1]
61 } grep {
62 1 $INC{$_->[0]}
63 } @candidates;
64  
65 1 ▶ if( ! @applicable_implementations ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@applicable_implementations) 1 0 1
66 1 @applicable_implementations = ($default, map {$_->[1]} @candidates);
67 }
68  
69 # Check which one we can load:
70 1 for my $impl (@applicable_implementations) {
71 1 ▶ if( eval "require $impl; 1" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval "require $impl; 1") 1 0 1
72 1 return $impl;
73 };
74 };
75  
76 # This will crash and burn, but that's how it is
77 0 eval "require $default; 1";
78 0 return $default;
79 };
80  
81 70 1;
82  
83 =head1 SUPPORTED BACKENDS
84  
85 The module will try to guess the best backend to use. The currently supported
86 backends are
87  
88 =over 4
89  
90 =item *
91  
92 L<IO::Async>
93  
94 This is the default backend
95  
96 =item *
97  
98 L<AnyEvent>
99  
100 This needs the following additional modules installed:
101  
102 L<AnyEvent::WebSocket::Client>
103  
104 L<AnyEvent::Future>
105  
106 =item *
107  
108 L<Mojolicious>
109  
110 This needs the following additional modules installed:
111  
112 L<Future::Mojo>
113  
114 =back
115  
116 If you want to substitute another backend, pass its class name instead
117 of this module which only acts as a factory.
118  
119 =head1 REPOSITORY
120  
121 The public repository of this module is
122 L<https://github.com/Corion/www-mechanize-chrome>.
123  
124 =head1 SUPPORT
125  
126 The public support forum of this module is L<https://perlmonks.org/>.
127  
128 =head1 BUG TRACKER
129  
130 Please report bugs in this module via the Github bug queue at
131 L<https://github.com/Corion/WWW-Mechanize-Chrome/issues>
132  
133 =head1 AUTHOR
134  
135 Max Maischein C<corion@cpan.org>
136  
137 =head1 COPYRIGHT (c)
138  
139 Copyright 2010-2026 by Max Maischein C<corion@cpan.org>.
140  
141 =head1 LICENSE
142  
143 This module is released under the same terms as Perl itself.
144  
145 =cut
« Chrome/DevToolsProtocol/Transport/NetAsync.pm ↑ Summary Chrome/DevToolsProtocol/Transport/Pipe/Mojo.pm »