| 1 | package Geo::IATA; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 4 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 4 | ▶ | use File::Spec; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 4 | ▶ | use DBI; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 4 | ▶ | use Sub::Install qw(install_sub); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 4 | ▶ | use version; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 4 | ▶ | use vars '$VERSION'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 4 | $VERSION = qv('0.0.3'); | |||||||||||||||||||
| 13 | 4 | our $AUTOLOAD; | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 2 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=14.2
Pod
documented
| |||||||||||||||||||||
| 16 | 2 | my $self = shift; | |||||||||||||||||||
| 17 | 2 | ▶ | my $pkg = ref $self || $self; | ||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 2 | my $path = shift; | |||||||||||||||||||
| 20 | 2 | ▶ | unless ($path){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 21 | 0 | my $db = $pkg; | |||||||||||||||||||
| 22 | 0 | $db =~s{::}{/}gxms; | |||||||||||||||||||
| 23 | 0 | $db =~s{$}{.pm}xms; | |||||||||||||||||||
| 24 | 0 | ($path = $INC{$db}) =~ s{.pm$}{}xms; | |||||||||||||||||||
| 25 | 0 | $path="iata_sqlite.db"; | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | 2 | my $dbh = DBI->connect("dbi:SQLite:dbname=$path","","", {RaiseError => 1, unicode=> 1}); | |||||||||||||||||||
| 29 | 2 | return bless {dbh => $dbh, dbname => $path}, $pkg; | |||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 9 | ▶ | sub AUTOLOAD { ## no critic qw(ClassHierarchies::ProhibitAutoloading Subroutines::RequireArgUnpacking) | ||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 33 | 9 | my $func = $AUTOLOAD; | |||||||||||||||||||
| 34 | 9 | $func =~ s/.*:://xms; | |||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 9 | ▶ | if ( grep { $func eq $_ } qw( iata icao airport location ) ) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 4 | ▶ | no strict 'refs'; ## no critic 'TestingAndDebugging::ProhibitNoStrict' | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | install_sub( | ||||||||||||||||||||
| 41 | 7 | ▶ | { code => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 42 | 7 | my $self = shift; | |||||||||||||||||||
| 43 | 7 | my $arg = shift; | |||||||||||||||||||
| 44 | 7 | my $sth = $self->dbh->prepare("select * from iata where $func like ?"); | |||||||||||||||||||
| 45 | 7 | $sth->execute($arg); | |||||||||||||||||||
| 46 | 7 | my $result = $sth->fetchall_arrayref( {} ); | |||||||||||||||||||
| 47 | 7 | $sth->finish; | |||||||||||||||||||
| 48 | 7 | return $result; | |||||||||||||||||||
| 49 | }, | ||||||||||||||||||||
| 50 | 3 | into => ref $_[0], | |||||||||||||||||||
| 51 | as => $func, | ||||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||
| 54 | 3 | goto &$func; | |||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | elsif ( $func =~ m/^(iata|icao|airport|location)2(iata|icao|airport|location)$/xms ) { | ||||||||||||||||||||
| 57 | 6 | my $from = $1; | |||||||||||||||||||
| 58 | 6 | my $to = $2; | |||||||||||||||||||
| 59 | 4 | ▶ | no strict 'refs'; ## no critic 'TestingAndDebugging::ProhibitNoStrict' | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | install_sub( | ||||||||||||||||||||
| 62 | 6 | ▶ | { code => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 63 | 6 | my $self = shift; | |||||||||||||||||||
| 64 | 6 | my $arg = shift; | |||||||||||||||||||
| 65 | 6 | return $self->$from($arg)->[0]{$to}; | |||||||||||||||||||
| 66 | }, | ||||||||||||||||||||
| 67 | 6 | into => ref $_[0], | |||||||||||||||||||
| 68 | as => $func, | ||||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | ); | ||||||||||||||||||||
| 71 | 6 | goto &$func; | |||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | else { | ||||||||||||||||||||
| 74 | 0 | croak "unknown subroutine $func"; | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | 0 | return; | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 2 | ▶ | sub DESTROY { | ||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=7.0
| |||||||||||||||||||||
| 80 | 2 | my $self = shift; | |||||||||||||||||||
| 81 | 2 | my $dbh = $self->dbh; | |||||||||||||||||||
| 82 | 2 | ▶ | if ($dbh){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 83 | 2 | $dbh->disconnect; | |||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | 2 | undef $self; | |||||||||||||||||||
| 86 | 2 | return; | |||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 9 | ▶ | sub dbh { | ||||||||||||||||||
|
Subroutine
dbh: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 90 | 9 | return shift->{dbh}; | |||||||||||||||||||
| 91 | } | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 4 | 1; # Magic true value required at end of module | |||||||||||||||||||
| 94 | __END__ | ||||||||||||||||||||