lib/Net/Camera/Sercomm/ICamera2.pm

filter: Statementstmt 42.8% 18 / 42 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 5 / 10 Podpod 100% 5 / 5 totaltotal 37.3% 28 / 75 SCAR 37.9
CC
10
Cov
30%
hostname
12.0
port
12.0
imageSettingsSize
12.0
CRAP 44.3
↑ Summary script/perl-Net-Camera-Sercomm-ICamera2-getSnapshot.pl »
1 package Net::Camera::Sercomm::ICamera2;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use base qw{Package::New};
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 our $VERSION = '0.01';
9 3 our $PACKAGE = __PACKAGE__;
10  
11 =head1 NAME
12  
13 Net::Camera::Sercomm::ICamera2 - Perl Interface for Sercomm ICamera2 network camera
14  
15 =head1 SYNOPSIS
16  
17 use Net::Camera::Sercomm::ICamera2;
18 my $camera = Net::Camera::Sercomm::ICamera2->new(hostname => 'mycamera.example.com');
19 my $jpeg = $camera->getSnapshot;
20  
21 =head1 DESCRIPTION
22  
23 The Sercomm ICamera2 is network camera that can be accessed via a web interface.
24 This module provides methods to retrieve an image from the camera.
25  
26 =head1 PROPERTIES
27  
28 =head2 hostname
29  
30 Required hostname or IP address
31  
32 =cut
33  
34 sub hostname {
35 0 ▶ my $self = shift;
Subroutine hostname: not called CC=3 SCAR=24.8
Pod documented
36 0 ▶ $self->{'hostname'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
37 0 ▶ die("Error: $PACKAGE property hostname required") unless defined $self->{'hostname'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"hostname"} 0 0 0
38 0 return $self->{'hostname'};
39 }
40  
41 =head2 port
42  
43 TCP/IP port
44  
45 Default: 80
46  
47 =cut
48  
49 sub port {
50 0 ▶ my $self = shift;
Subroutine port: not called CC=3 SCAR=24.8
Pod documented
51 0 ▶ $self->{'port'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
52 0 ▶ $self->{'port'} = 80 unless defined $self->{'port'};;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"port"} 0 0 0
53 0 return $self->{'port'};
54 }
55  
56 =head2 imageSettingsSize
57  
58 Image size setting passed on the getSnapshot URL.
59  
60 size=2 320x240
61 size=3 640x480
62 size=4 1280x720
63  
64 Default: 4
65  
66 All other values return 320x240
67  
68 =cut
69  
70 sub imageSettingsSize {
71 0 ▶ my $self = shift;
Subroutine imageSettingsSize: not called CC=3 SCAR=24.8
Pod documented
72 0 ▶ $self->{'imageSettingsSize'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
73 0 ▶ $self->{'imageSettingsSize'} = 4 unless defined $self->{'imageSettingsSize'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"imageSettingsSize"} 0 0 0
74 0 return $self->{'imageSettingsSize'};
75 }
76  
77 =head2 imageSettingsQuality
78  
79 Image JPEG compression quality setting passed on the getSnapshot URL.
80  
81 quality=1 JPEG quality 85
82 quality=2 JPEG quality 70
83 quality=3 JPEG quality 55
84 quality=4 JPEG quality 40
85 quality=5 JPEG quality 25
86  
87 Default: 1
88  
89 =cut
90  
91 sub imageSettingsQuality {
92 0 ▶ my $self = shift;
Subroutine imageSettingsQuality: not called CC=3 SCAR=24.8
Pod documented
93 0 ▶ $self->{'imageSettingsQuality'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
94 0 ▶ $self->{'imageSettingsQuality'} = 1 unless defined $self->{'imageSettingsQuality'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"imageSettingsQuality"} 0 0 0
95 0 return $self->{'imageSettingsQuality'};
96 }
97  
98 =head1 METHODS
99  
100 =head2 getSnapshot
101  
102 Returns a JPEG image.
103  
104 =cut
105  
106 sub getSnapshot {
107 0 ▶ my $self = shift;
Subroutine getSnapshot: not called CC=2 SCAR=17.9
Pod documented
108 0 my $ua = LWP::UserAgent->new; $ua->agent("Mozilla/5.0 (compatible; $PACKAGE/$VERSION; See rt.cpan.org 35173)");
109 0 my $url = sprintf("http://%s:%s/img/snapshot.cgi?size=%s&quality=%s",
110 $self->hostname, $self->port, $self->imageSettingsSize, $self->imageSettingsQuality);
111 0 my $request = HTTP::Request->new(GET => $url);
112 0 my $response = $ua->request($request); #isa HTTP::Response
113 0 ▶ die(sprintf("HTTP Error: %s", $response->status_line)) unless $response->is_success;
Branch: 1 branch
BranchTrueFalseTotal
unless $response->is_success 0 0 0
114 0 return $response->content;
115 }
116  
117 =head1 SEE ALSO
118  
119 https://github.com/edent/Sercomm-API, L<Net::Camera::Edimax::IC1500>
120  
121 =head1 AUTHOR
122  
123 Michael R. Davis mrdvt at cpan
124  
125 =head1 COPYRIGHT AND LICENSE
126  
127 Copyright (C) 2020 by Michael R. Davis
128  
129 Permission is hereby granted, free of charge, to any person obtaining a copy
130 of this software and associated documentation files (the "Software"), to deal
131 in the Software without restriction, including without limitation the rights
132 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
133 copies of the Software, and to permit persons to whom the Software is
134 furnished to do so, subject to the following conditions:
135  
136 The above copyright notice and this permission notice shall be included in all
137 copies or substantial portions of the Software.
138  
139 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
140 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
141 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
142 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
143 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
144 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
145 SOFTWARE.
146  
147 =cut
148  
149 3 1;
↑ Summary script/perl-Net-Camera-Sercomm-ICamera2-getSnapshot.pl »