File Coverage

blib/lib/Pinto/Chrome/Net.pm
Criterion Covered Total %
statement 29 40 72.5
branch 6 18 33.3
condition 1 2 50.0
subroutine 7 10 70.0
pod 0 4 0.0
total 43 74 58.1


line stmt bran cond sub pod time code
1             # ABSTRACT: Interface for network-based interaction
2              
3             package Pinto::Chrome::Net;
4              
5 12     12   72 use Moose;
  12         26  
  12         78  
6 12     12   69850 use MooseX::StrictConstructor;
  12         24  
  12         110  
7 12     12   33390 use MooseX::MarkAsMethods ( autoclean => 1 );
  12         24  
  12         110  
8              
9 12     12   37220 use Pinto::Types qw(Io);
  12         38  
  12         104  
10 12     12   65582 use Pinto::Util qw(itis);
  12         24  
  12         680  
11 12     12   74 use Pinto::Constants qw(:protocol);
  12         26  
  12         708  
12              
13             #-----------------------------------------------------------------------------
14              
15             our $VERSION = '0.13'; # VERSION
16              
17             #-----------------------------------------------------------------------------
18              
19             extends qw( Pinto::Chrome::Term );
20              
21             #-----------------------------------------------------------------------------
22              
23             has stdout => (
24             is => 'ro',
25             isa => Io,
26             required => 1,
27             coerce => 1,
28             );
29              
30             has stderr => (
31             is => 'ro',
32             isa => Io,
33             required => 1,
34             coerce => 1,
35             );
36              
37             #-----------------------------------------------------------------------------
38              
39             sub diag {
40 5     5 0 21 my ( $self, $msg, $opts ) = @_;
41              
42 5   50     20 $opts ||= {};
43              
44 5 50       34 $msg = $msg->() if ref $msg eq 'CODE';
45              
46 5 100       45 if ( itis( $msg, 'Pinto::Exception' ) ) {
47              
48             # Show full stack trace if we are debugging
49 4 50       82 $msg = $ENV{PINTO_DEBUG} ? $msg->as_string : $msg->message;
50             }
51              
52 5         98 chomp $msg;
53 5         115 $msg = $self->colorize( $msg, $opts->{color} );
54 5 50       114 $msg .= "\n" unless $opts->{no_newline};
55              
56             # Prepend prefix to each line (not just at the start of the message)
57             # The prefix is used by Pinto::Remote to distinguish between
58             # messages that go to stderr and those that should go to stdout
59 5         46 $msg =~ s/^/$PINTO_PROTOCOL_DIAG_PREFIX/gmx;
60              
61 5 50       57 print { $self->stderr } $msg or croak $!;
  5         140  
62             }
63              
64             #-----------------------------------------------------------------------------
65              
66             sub show_progress {
67 0     0 0   my ($self) = @_;
68              
69 0 0         return if not $self->should_render_progress;
70              
71 0           $self->stderr->autoflush; # Make sure pipes are hot
72              
73 0 0         print { $self->stderr } $PINTO_PROTOCOL_PROGRESS_MESSAGE . "\n" or croak $!;
  0            
74             }
75              
76             #-----------------------------------------------------------------------------
77              
78             sub should_render_progress {
79 0     0 0   my ($self) = @_;
80              
81 0 0         return 0 if $self->verbose;
82 0 0         return 0 if $self->quiet;
83 0           return 1;
84             }
85              
86             #-----------------------------------------------------------------------------
87              
88             sub edit {
89 0     0 0   my ( $self, $document ) = @_;
90              
91 0           return $document; # TODO!
92             }
93              
94             #-----------------------------------------------------------------------------
95              
96             __PACKAGE__->meta->make_immutable;
97              
98             #-----------------------------------------------------------------------------
99             1;
100              
101             __END__
102              
103             =pod
104              
105             =encoding UTF-8
106              
107             =for :stopwords Jeffrey Ryan Thalhammer
108              
109             =head1 NAME
110              
111             Pinto::Chrome::Net - Interface for network-based interaction
112              
113             =head1 VERSION
114              
115             version 0.13
116              
117             =head1 AUTHOR
118              
119             Jeffrey Ryan Thalhammer <jeff@stratopan.com>
120              
121             =head1 COPYRIGHT AND LICENSE
122              
123             This software is copyright (c) 2015 by Jeffrey Ryan Thalhammer.
124              
125             This is free software; you can redistribute it and/or modify it under
126             the same terms as the Perl 5 programming language system itself.
127              
128             =cut