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