ARDrone/Video/BuildIO.pm

filter: Statementstmt 72.7% 16 / 22 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 100% 1 / 1 totaltotal 70.9% 22 / 31 CC 2 SCAR 8.9
CC
2
Cov
67%
_build_io
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.4
« ARDrone/Video.pm ↑ Summary ARDrone/Video/Fileno.pm »
1 # Copyright (c) 2015 Timm Murray
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are met:
6 #
7 # * Redistributions of source code must retain the above copyright notice,
8 # this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution.
12 #
13 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23 # POSSIBILITY OF SUCH DAMAGE.
24 package UAV::Pilot::ARDrone::Video::BuildIO;
25 7 $UAV::Pilot::ARDrone::Video::BuildIO::VERSION = '1.0';
26 7 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 7 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30  
31 sub _build_io
32 {
33 0 ▶ my ($class, $args) = @_;
Subroutine _build_io: not called CC=2 SCAR=17.9
34 0 my $driver = $$args{driver};
35 0 my $host = $driver->host;
36 0 my $port = $driver->ARDRONE_PORT_VIDEO_H264;
37  
38 0 ▶ my $io = IO::Socket::INET->new(
Branch: 1 branch
BranchTrueFalseTotal
my $io = "IO::Socket::INET"->new("PeerAddr", $host, "PeerPort", $port, "ReuseAddr", 1, "Blocking", 0) or "UAV::Pilot::IOException"->throw("error", "Could not connect to ${host}:$port for video: $@") 0 0 0
39 PeerAddr => $host,
40 PeerPort => $port,
41 ReuseAddr => 1,
42 Blocking => 0,
43 ) or UAV::Pilot::IOException->throw(
44 error => "Could not connect to $host:$port for video: $@",
45 );
46 0 return $io;
47 }
48  
49 sub init_event_loop
50 {
51 4 ▶ my ($self) = @_;
Subroutine init_event_loop: called CC=1 SCAR=0.0
Pod documented
52  
53 4 my $io_event; $io_event = AnyEvent->io(
54 fh => $self->_io,
55 poll => 'r',
56 cb => sub {
57 15720 ▶ $self->_process_io;
Subroutine __ANON__: called CC=1 SCAR=0.0
58 15720 $io_event;
59 },
60 4 );
61 4 return 1;
62 }
63  
64  
65 7 1;
66 __END__
67  
68  
69 =head1 NAME
70  
71 UAV::Pilot::ARDrone::Video::BuildIO
72  
73 =head1 DESCRIPTION
74  
75 Role for video stream handling modules to create the socket for reading the
76 stream from the Parrot AR.Drone. Also sets up the AnyEvent io watcher.
77  
78 =head1 PROVIDES
79  
80 =head2 _build_io
81  
82 $class->_build_io({ driver => $driver })
83  
84 Passed a C<UAV::Pilot::ARDrone::Driver>. Sets up and returns a
85 C<IO::Socket::INET> object that connects to the host and video port for the
86 AR.Drone.
87  
88 =head2 init_event_loop
89  
90 Called to setup an AnyEvent io watcher to process the incoming video data.
91  
92 =head1 REQUIRES
93  
94 =head2 _io
95  
96 Returns a filehandle for reading video data.
97  
98 =head2 _process_io
99  
100 Called when there is IO data to read from C<_io>.
101  
102 =cut
« ARDrone/Video.pm ↑ Summary ARDrone/Video/Fileno.pm »