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