File Coverage

blib/lib/Net/Camera/Sercomm/ICamera2.pm
Criterion Covered Total %
statement 15 39 38.4
branch 0 18 0.0
condition n/a
subroutine 5 10 50.0
pod 5 5 100.0
total 25 72 34.7


line stmt bran cond sub pod time code
1             package Net::Camera::Sercomm::ICamera2;
2 2     2   138410 use strict;
  2         15  
  2         63  
3 2     2   10 use warnings;
  2         4  
  2         60  
4 2     2   11 use base qw{Package::New};
  2         4  
  2         1053  
5 2     2   1902 use LWP::UserAgent;
  2         96139  
  2         78  
6 2     2   20 use HTTP::Request;
  2         5  
  2         763  
7              
8             our $VERSION = '0.01';
9             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     0 1   my $self = shift;
36 0 0         $self->{'hostname'} = shift if @_;
37 0 0         die("Error: $PACKAGE property hostname required") unless defined $self->{'hostname'};
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     0 1   my $self = shift;
51 0 0         $self->{'port'} = shift if @_;
52 0 0         $self->{'port'} = 80 unless defined $self->{'port'};;
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     0 1   my $self = shift;
72 0 0         $self->{'imageSettingsSize'} = shift if @_;
73 0 0         $self->{'imageSettingsSize'} = 4 unless defined $self->{'imageSettingsSize'};
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     0 1   my $self = shift;
93 0 0         $self->{'imageSettingsQuality'} = shift if @_;
94 0 0         $self->{'imageSettingsQuality'} = 1 unless defined $self->{'imageSettingsQuality'};
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     0 1   my $self = shift;
108 0           my $ua = LWP::UserAgent->new; $ua->agent("Mozilla/5.0 (compatible; $PACKAGE/$VERSION; See rt.cpan.org 35173)");
  0            
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 0         die(sprintf("HTTP Error: %s", $response->status_line)) unless $response->is_success;
114 0           return $response->content;
115             }
116              
117             =head1 SEE ALSO
118              
119             https://github.com/edent/Sercomm-API, L
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             1;