| 1 | 7 | ▶ | use 5.10.0; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 2 | 7 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 7 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | package OpenGbg::Service::TrafficCamera::GetCameraImage; | ||
| 6 | |||
| 7 | # ABSTRACT: Get the current image from a traffic camera | ||
| 8 | 7 | our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY | |
| 9 | 7 | our $VERSION = '0.1402'; | |
| 10 | |||
| 11 | 7 | ▶ | use OpenGbg::Elk; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | 7 | ▶ | use namespace::autoclean; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | 7 | ▶ | use Types::Standard qw/Int/; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | 7 | ▶ | use OpenGbg::DateTimeType qw/DateTime/; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 15 | |||
| 16 | 7 | ▶ | use DateTime; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 17 | |||
| 18 | 7 | has image => ( | |
| 19 | is => 'ro', | ||
| 20 | ); | ||
| 21 | 7 | has image_size => ( | |
| 22 | is => 'ro', | ||
| 23 | isa => Int, | ||
| 24 | lazy => 1, | ||
| 25 | builder => 1, | ||
| 26 | ); | ||
| 27 | 7 | has timestamp => ( | |
| 28 | is => 'ro', | ||
| 29 | isa => DateTime, | ||
| 30 | lazy => 1, | ||
| 31 | builder => 1, | ||
| 32 | ); | ||
| 33 | |||
| 34 | sub _build_image_size { | ||
| 35 | 0 | ▶ | return length shift->image; |
|
Subroutine
_build_image_size: not called CC=1 SCAR=6.9
| |||
| 36 | } | ||
| 37 | |||
| 38 | sub _build_timestamp { | ||
| 39 | 0 | ▶ | my $datetime = DateTime::->now->truncate(to => 'minute')->set_time_zone('Europe/Stockholm'); |
|
Subroutine
_build_timestamp: not called CC=1 SCAR=6.9
| |||
| 40 | } | ||
| 41 | |||
| 42 | 7 | __PACKAGE__->meta->make_immutable; | |
| 43 | |||
| 44 | 7 | 1; | |
| 45 | |||
| 46 | __END__ | ||
| 47 | |||
| 48 | =pod | ||
| 49 | |||
| 50 | =encoding utf-8 | ||
| 51 | |||
| 52 | =head1 NAME | ||
| 53 | |||
| 54 | OpenGbg::Service::TrafficCamera::GetCameraImage - Get the current image from a traffic camera | ||
| 55 | |||
| 56 | =head1 VERSION | ||
| 57 | |||
| 58 | Version 0.1402, released 2016-08-12. | ||
| 59 | |||
| 60 | =head1 SYNOPSIS | ||
| 61 | |||
| 62 | use Path::Tiny; | ||
| 63 | |||
| 64 | my $camera_id = 30; | ||
| 65 | my $traffic_camera_service = OpenGbg->new->traffic_camera; | ||
| 66 | my $get_camera_image = $traffic_camera_service->get_camera_image($camera_id); | ||
| 67 | |||
| 68 | say sprintf '%s bytes', $get_camera_image->size; | ||
| 69 | path(sprintf 'image-%s-%s.jpg', time, $camera_id)->spew($get_camera_image->image); | ||
| 70 | |||
| 71 | =head1 ATTRIBUTES | ||
| 72 | |||
| 73 | =head2 image_size | ||
| 74 | |||
| 75 | Integer. The image size in bytes. Sometimes cameras are out-of-order, and returns a dummy image. These are at the time of writing less than 10kb, and is therefore useful to filter on (if these images are unwanted). | ||
| 76 | |||
| 77 | =head2 timestamp | ||
| 78 | |||
| 79 | A L<DateTime> object, rounded down to the closest minute. The timestamp of the image is not given in the response from the web service. This DateTime object is created as a convenience. | ||
| 80 | |||
| 81 | =head1 SOURCE | ||
| 82 | |||
| 83 | L<https://github.com/Csson/p5-OpenGbg> | ||
| 84 | |||
| 85 | =head1 HOMEPAGE | ||
| 86 | |||
| 87 | L<https://metacpan.org/release/OpenGbg> | ||
| 88 | |||
| 89 | =head1 AUTHOR | ||
| 90 | |||
| 91 | Erik Carlsson <info@code301.com> | ||
| 92 | |||
| 93 | =head1 COPYRIGHT AND LICENSE | ||
| 94 | |||
| 95 | This software is copyright (c) 2016 by Erik Carlsson. | ||
| 96 | |||
| 97 | This is free software; you can redistribute it and/or modify it under | ||
| 98 | the same terms as the Perl 5 programming language system itself. | ||
| 99 | |||
| 100 | =cut | ||