| 1 | package Chrome::DevToolsProtocol::Transport::NetAsync; | ||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 1 | ▶ | use Moo 2; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | no warnings 'experimental::signatures'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use feature 'signatures'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use Scalar::Util 'weaken'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use IO::Async::Loop; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | with 'MooX::Role::EventEmitter'; | |||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 1 | ▶ | use Net::Async::WebSocket::Client; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 1 | Net::Async::WebSocket::Client->VERSION(0.12); # fixes some errors with masked frames | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 1 | our $VERSION = '0.80'; | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | =head1 NAME | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | Chrome::DevToolsProtocol::Transport::NetAsync - IO::Async backend for Chrome communication | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | my $got_endpoint = Future->done( "ws://..." ); | ||||||||||||||||||||
| 23 | my $t = Chrome::DevToolsProtocol::Transport::NetAsync->new; | ||||||||||||||||||||
| 24 | $t->connect( $handler, $got_endpoint, $logger) | ||||||||||||||||||||
| 25 | ->then(sub { | ||||||||||||||||||||
| 26 | my( $connection ) = @_; | ||||||||||||||||||||
| 27 | print "We are connected\n"; | ||||||||||||||||||||
| 28 | }); | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | =cut | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 1 | has 'type' => ( | |||||||||||||||||||
| 33 | is => 'ro', | ||||||||||||||||||||
| 34 | default => 'websocket' | ||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | has 'loop' => ( | ||||||||||||||||||||
| 38 | is => 'lazy', | ||||||||||||||||||||
| 39 | 0 | ▶ | default => sub { IO::Async::Loop->new() }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 40 | 1 | ); | |||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 1 | has 'connection' => ( | |||||||||||||||||||
| 43 | is => 'rw', | ||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 0 | ▶ | sub connect( $self, $handler, $got_endpoint, $logger ) { | ||||||||||||||||||
|
Subroutine
connect: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 47 | 0 | ▶ | $logger ||= sub{}; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$logger ||= sub {
}
MC/DC0%0/2
$logger ||= sub {
}
$logger
sub {
}
Truth table0%0/3
A ||= B
A= $loggerB= sub {
}
| |||||||||||||||||||||
| 48 | 0 | weaken $handler; | |||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 0 | weaken( my $s = $self ); | |||||||||||||||||||
| 51 | 0 | my $client; | |||||||||||||||||||
| 52 | 0 | ▶ | $got_endpoint->then( sub( $endpoint ) { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 53 | $client = Net::Async::WebSocket::Client->new( | ||||||||||||||||||||
| 54 | # Kick off the continous polling | ||||||||||||||||||||
| 55 | 0 | ▶ | on_frame => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 56 | 0 | my( $connection, $message )=@_; | |||||||||||||||||||
| 57 | 0 | ▶ | if( $handler ) { # may have gone away already | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | 0 | $handler->on_response( $connection, $message ) | |||||||||||||||||||
| 59 | }; | ||||||||||||||||||||
| 60 | }, | ||||||||||||||||||||
| 61 | 0 | ▶ | on_read_eof => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 62 | 0 | my( $connection )=@_; | |||||||||||||||||||
| 63 | 0 | $logger->('info', "Connection closed"); | |||||||||||||||||||
| 64 | # TODO: should we tell handler? | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 0 | ▶ | $s->emit('closed') | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 67 | if( $s ); | ||||||||||||||||||||
| 68 | }, | ||||||||||||||||||||
| 69 | 0 | ); | |||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | # Patch unlimited frame size into the client so we can receive large | ||||||||||||||||||||
| 72 | # buffers. This should become an RT ticket against Net::Async::WebSocket::Client | ||||||||||||||||||||
| 73 | 0 | $client->{framebuffer} = Protocol::WebSocket::Frame->new( | |||||||||||||||||||
| 74 | max_payload_size => undef | ||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 0 | $self->loop->add( $client ); | |||||||||||||||||||
| 78 | 0 | ▶ | $self->{connection} ||= $client; | ||||||||||||||||||
|
Condition0%0/3
$self->{"connection"} ||= $client
MC/DC0%0/2
$self->{"connection"} ||= $client
$self->{"connection"}
$client
Truth table0%0/3
A ||= B
A= $self->{"connection"}B= $client
| |||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 0 | ▶ | die "Got an undefined endpoint" unless defined $endpoint; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 81 | 0 | $logger->('debug',"Connecting to $endpoint"); | |||||||||||||||||||
| 82 | 0 | ▶ | $client->connect( url => $endpoint, on_connected => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 83 | 0 | $logger->('info',"Connected to $endpoint"); | |||||||||||||||||||
| 84 | 0 | } ); | |||||||||||||||||||
| 85 | 0 | ▶ | })->catch(sub{ | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 86 | #require Data::Dumper; | ||||||||||||||||||||
| 87 | #warn "caught"; | ||||||||||||||||||||
| 88 | #warn Data::Dumper::Dumper( \@_ ); | ||||||||||||||||||||
| 89 | 0 | Future->fail( @_ ); | |||||||||||||||||||
| 90 | 0 | }); | |||||||||||||||||||
| 91 | } | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 0 | ▶ | sub send( $self, $message ) { | ||||||||||||||||||
|
Subroutine
send: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 94 | 0 | $self->connection->send_text_frame( $message ) | |||||||||||||||||||
| 95 | } | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | 0 | ▶ | sub close( $self ) { | ||||||||||||||||||
|
Subroutine
close: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 98 | 0 | my $c = delete $self->{connection}; | |||||||||||||||||||
| 99 | 0 | ▶ | if( $c) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 100 | 0 | $c->close | |||||||||||||||||||
| 101 | }; | ||||||||||||||||||||
| 102 | } | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | 0 | ▶ | sub future( $self ) { | ||||||||||||||||||
|
Subroutine
future: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 105 | 0 | my $res = $self->loop->new_future; | |||||||||||||||||||
| 106 | 0 | return $res | |||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | =head2 C<< $transport->sleep( $seconds ) >> | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | $transport->sleep( 10 )->get; # wait for 10 seconds | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | Returns a Future that will be resolved in the number of seconds given. | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | =cut | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | 0 | ▶ | sub sleep( $self, $seconds ) { | ||||||||||||||||||
|
Subroutine
sleep: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 118 | 0 | $self->loop->delay_future( after => $seconds ) | |||||||||||||||||||
| 119 | } | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | 1 | 1; | |||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | =head1 REPOSITORY | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | The public repository of this module is | ||||||||||||||||||||
| 126 | L<https://github.com/Corion/www-mechanize-chrome>. | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | =head1 SUPPORT | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | The public support forum of this module is L<https://perlmonks.org/>. | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | =head1 BUG TRACKER | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | Please report bugs in this module via the Github bug queue at | ||||||||||||||||||||
| 135 | L<https://github.com/Corion/WWW-Mechanize-Chrome/issues> | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | =head1 AUTHOR | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | Max Maischein C<corion@cpan.org> | ||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | =head1 COPYRIGHT (c) | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | Copyright 2010-2026 by Max Maischein C<corion@cpan.org>. | ||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | =head1 LICENSE | ||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | This module is released under the same terms as Perl itself. | ||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | =cut | ||||||||||||||||||||