| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Image::ExifTool::Location; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 2 |  |  | 2 |  | 293015 | use warnings; | 
|  | 2 |  |  |  |  | 7 |  | 
|  | 2 |  |  |  |  | 73 |  | 
| 4 | 2 |  |  | 2 |  | 12 | use strict; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 71 |  | 
| 5 | 2 |  |  | 2 |  | 31 | use Carp; | 
|  | 2 |  |  |  |  | 10 |  | 
|  | 2 |  |  |  |  | 571 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 2 |  |  | 2 |  | 2458 | use version; our $VERSION = qv( '0.0.4' ); | 
|  | 2 |  |  |  |  | 6048 |  | 
|  | 2 |  |  |  |  | 12 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | sub new { | 
| 10 | 0 |  |  | 0 | 1 | 0 | croak "Call Image::ExifTool->new() instead of " . __PACKAGE__ . "->new()"; | 
| 11 |  |  |  |  |  |  | } | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | # Reopen Image::ExifTool | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | package Image::ExifTool; | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 2 |  |  | 2 |  | 958 | use warnings; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 69 |  | 
| 18 | 2 |  |  | 2 |  | 9 | use strict; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 51 |  | 
| 19 | 2 |  |  | 2 |  | 10 | use Carp; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 140 |  | 
| 20 | 2 |  |  | 2 |  | 549379 | use Image::ExifTool; | 
|  | 2 |  |  |  |  | 242343 |  | 
|  | 2 |  |  |  |  | 1083 |  | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | my @LOC_TAGS = qw( | 
| 23 |  |  |  |  |  |  | GPSLatitude     GPSLatitudeRef | 
| 24 |  |  |  |  |  |  | GPSLongitude    GPSLongitudeRef | 
| 25 |  |  |  |  |  |  | ); | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | my @ELE_TAGS = qw( | 
| 28 |  |  |  |  |  |  | GPSAltitude     GPSAltitudeRef | 
| 29 |  |  |  |  |  |  | ); | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | my @GROUP = ( Group => 'GPS' ); | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | sub _has_all { | 
| 34 | 84 |  |  | 84 |  | 173 | my $self = shift; | 
| 35 | 84 |  |  |  |  | 316 | for ( @_ ) { | 
| 36 | 196 | 100 |  |  |  | 75378 | return unless defined( $self->GetValue( $_ ) ); | 
| 37 |  |  |  |  |  |  | } | 
| 38 | 42 |  |  |  |  | 2084 | return 1; | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | sub HasLocation { | 
| 42 | 70 |  |  | 70 | 0 | 943987 | my $self = shift; | 
| 43 | 70 |  |  |  |  | 344 | return $self->_has_all( @LOC_TAGS ); | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | sub HasElevation { | 
| 47 | 14 |  |  | 14 | 0 | 108304 | my $self = shift; | 
| 48 | 14 |  |  |  |  | 73 | return $self->_has_all( @ELE_TAGS ); | 
| 49 |  |  |  |  |  |  | } | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | sub _set_latlon { | 
| 52 | 70 |  |  | 70 |  | 122 | my $self = shift; | 
| 53 | 70 |  |  |  |  | 262 | my ( $name, $latlon, @sign_flags ) = @_; | 
| 54 |  |  |  |  |  |  |  | 
| 55 | 70 |  |  |  |  | 408 | $self->SetNewValue( $name, abs( $latlon ), @GROUP, Type => 'ValueConv' ); | 
| 56 | 70 | 100 |  |  |  | 240941 | $self->SetNewValue( | 
| 57 |  |  |  |  |  |  | $name . 'Ref', | 
| 58 |  |  |  |  |  |  | $sign_flags[ $latlon < 0 ? 1 : 0 ], | 
| 59 |  |  |  |  |  |  | @GROUP, Type => 'ValueConv' | 
| 60 |  |  |  |  |  |  | ); | 
| 61 |  |  |  |  |  |  | } | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | sub SetLocation { | 
| 64 | 35 |  |  | 35 | 0 | 96 | my $self = shift; | 
| 65 | 35 |  |  |  |  | 74 | my ( $lat, $lon ) = @_; | 
| 66 |  |  |  |  |  |  |  | 
| 67 | 35 | 50 |  |  |  | 130 | croak "SetLocation must be called with the latitude and longitude" | 
| 68 |  |  |  |  |  |  | unless defined( $lon ); | 
| 69 |  |  |  |  |  |  |  | 
| 70 | 35 |  |  |  |  | 151 | $self->_set_latlon( 'GPSLatitude',  $lat, qw(N S) ); | 
| 71 | 35 |  |  |  |  | 12844 | $self->_set_latlon( 'GPSLongitude', $lon, qw(E W) ); | 
| 72 |  |  |  |  |  |  | } | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | sub SetElevation { | 
| 75 | 7 |  |  | 7 | 0 | 15 | my $self = shift; | 
| 76 | 7 |  |  |  |  | 39 | my ( $ele ) = @_; | 
| 77 |  |  |  |  |  |  |  | 
| 78 | 7 | 50 |  |  |  | 35 | croak "SetElevation must be called with the elevation in metres" | 
| 79 |  |  |  |  |  |  | unless defined( $ele ); | 
| 80 |  |  |  |  |  |  |  | 
| 81 | 7 |  |  |  |  | 67 | $self->SetNewValue( 'GPSAltitude', abs( $ele ), | 
| 82 |  |  |  |  |  |  | @GROUP, Type => 'ValueConv' ); | 
| 83 | 7 | 100 |  |  |  | 5891 | $self->SetNewValue( 'GPSAltitudeRef', $ele < 0 ? '1' : '0', | 
| 84 |  |  |  |  |  |  | @GROUP, Type => 'ValueConv' ); | 
| 85 |  |  |  |  |  |  | } | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | sub GetLocation { | 
| 88 | 35 |  |  | 35 | 0 | 83 | my $self = shift; | 
| 89 |  |  |  |  |  |  |  | 
| 90 | 35 | 50 |  |  |  | 156 | wantarray or croak "GetLocation must be called in a list context"; | 
| 91 |  |  |  |  |  |  | return | 
| 92 | 35 |  |  |  |  | 74 | map { $self->GetValue( $_, 'ValueConv' ) } qw(GPSLatitude GPSLongitude); | 
|  | 70 |  |  |  |  | 8139 |  | 
| 93 |  |  |  |  |  |  | } | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | sub GetElevation { | 
| 96 | 7 |  |  | 7 | 0 | 16 | my $self = shift; | 
| 97 | 7 |  |  |  |  | 33 | my $v    = $self->GetValue( 'GPSAltitude', 'Raw' ); | 
| 98 | 7 |  |  |  |  | 163 | my $r    = $self->GetValue( 'GPSAltitudeRef', 'Raw' ); | 
| 99 |  |  |  |  |  |  |  | 
| 100 | 7 | 50 | 33 |  |  | 168 | return unless defined( $v ) && defined( $r ); | 
| 101 | 7 | 100 |  |  |  | 45 | return $v * ( $r == 0 ? 1 : -1 ); | 
| 102 |  |  |  |  |  |  | } | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | 1; | 
| 105 |  |  |  |  |  |  | __END__ |