| 1 | package App::perlrdf::Command; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | $App::perlrdf::Command::AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||
| 10 | 2 | $App::perlrdf::Command::VERSION = '0.006'; | |||||||||||||||||||||||||||
| 11 | } | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use App::Cmd::Setup -command; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use constant store_opt_spec => ( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | [ 'database|t=s' => '"sqlite", "mysql" or "pg"' ], | ||||||||||||||||||||||||||||
| 17 | [ 'dbname|d=s' => 'Database name (file name for SQLite)' ], | ||||||||||||||||||||||||||||
| 18 | [ 'host|h=s' => 'Database server host name or IP address' ], | ||||||||||||||||||||||||||||
| 19 | [ 'port=i' => 'Database server port' ], | ||||||||||||||||||||||||||||
| 20 | [ 'username|u=s' => 'User name for database login' ], | ||||||||||||||||||||||||||||
| 21 | [ 'password=s' => 'Password for database login' ], | ||||||||||||||||||||||||||||
| 22 | []=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>, | ||||||||||||||||||||||||||||
| 23 | [ 'dbi|D=s' => 'DBI DSN' ], | ||||||||||||||||||||||||||||
| 24 | [ 'sqlite|Q=s' => 'SQLite file name' ], | ||||||||||||||||||||||||||||
| 25 | []=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>, | ||||||||||||||||||||||||||||
| 26 | [ 'store|T=s' => 'Trine store configuration string' ], | ||||||||||||||||||||||||||||
| 27 | [ 'model|M=s' => 'Database model name (defaults to "")' ], | ||||||||||||||||||||||||||||
| 28 | 2 | ); | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 2 | ▶ | use constant store_help => q( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | The database to connect to can be specified using the 'database', 'dbname', | ||||||||||||||||||||||||||||
| 32 | 'host', 'port', 'username' and 'password' options. Alternatively you can | ||||||||||||||||||||||||||||
| 33 | specify an exact DBI DSN (in which case the 'database', 'dbname', 'host' and | ||||||||||||||||||||||||||||
| 34 | 'port' options must not be specified). The 'sqlite' option is a shortcut for | ||||||||||||||||||||||||||||
| 35 | setting the 'database' option to 'sqlite', and setting the 'dbname' option. | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | Alternatively, you may specify an RDF::Trine::Store configuration string. | ||||||||||||||||||||||||||||
| 38 | If you want to connect to a non-DBI store, this is the only way to specify | ||||||||||||||||||||||||||||
| 39 | it. | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | Several DBI-based stores can share the same SQL database. This is achieved | ||||||||||||||||||||||||||||
| 42 | by giving them each a different model name (which confusingly has nothing to | ||||||||||||||||||||||||||||
| 43 | do with the RDF::Trine::Model class!). | ||||||||||||||||||||||||||||
| 44 | 2 | ); | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | sub get_filespecs | ||||||||||||||||||||||||||||
| 47 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get_filespecs: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 48 | 0 | my ($self, $class, $name, $opt) = @_; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | my @specs = map { | ||||||||||||||||||||||||||||
| 51 | $class->new_from_filespec( | ||||||||||||||||||||||||||||
| 52 | $_, | ||||||||||||||||||||||||||||
| 53 | $opt->{$name.'_format'}, | ||||||||||||||||||||||||||||
| 54 | 0 | $opt->{$name.'_base'}, | |||||||||||||||||||||||||||
| 55 | ) | ||||||||||||||||||||||||||||
| 56 | 0 | } do { | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | if (ref $opt->{$name.'_spec'} eq 'ARRAY') | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 58 | 0 | { @{$opt->{$name.'_spec'}} } | |||||||||||||||||||||||||||
| 59 | elsif (defined $opt->{$name.'_spec'}) | ||||||||||||||||||||||||||||
| 60 | 0 | { ($opt->{$name.'_spec'}) } | |||||||||||||||||||||||||||
| 61 | else | ||||||||||||||||||||||||||||
| 62 | 0 | { qw() } | |||||||||||||||||||||||||||
| 63 | }; | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | push @specs, map { | ||||||||||||||||||||||||||||
| 66 | $class->new_from_filespec( | ||||||||||||||||||||||||||||
| 67 | "{}$_", | ||||||||||||||||||||||||||||
| 68 | $opt->{$name.'_format'}, | ||||||||||||||||||||||||||||
| 69 | 0 | $opt->{$name.'_base'}, | |||||||||||||||||||||||||||
| 70 | ) | ||||||||||||||||||||||||||||
| 71 | 0 | } do { | |||||||||||||||||||||||||||
| 72 | 0 | ▶ | if (ref $opt->{$name} eq 'ARRAY') | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 73 | 0 | { @{$opt->{$name}} } | |||||||||||||||||||||||||||
| 74 | elsif (defined $opt->{$name}) | ||||||||||||||||||||||||||||
| 75 | 0 | { ($opt->{$name}) } | |||||||||||||||||||||||||||
| 76 | else | ||||||||||||||||||||||||||||
| 77 | 0 | { qw() } | |||||||||||||||||||||||||||
| 78 | }; | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | return @specs; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | sub get_store | ||||||||||||||||||||||||||||
| 84 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get_store: not called CC=23 SCAR=62.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 85 | 0 | require RDF::Trine; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | my ($self, $opt) = @_; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | my %exclusions = ( | |||||||||||||||||||||||||||
| 90 | store => [qw[ dbi sqlite username password host port dbname database ]], | ||||||||||||||||||||||||||||
| 91 | sqlite => [qw[ dbi username password host port dbname database ]], | ||||||||||||||||||||||||||||
| 92 | dbi => [qw[ host port dbname database ]], | ||||||||||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | foreach my $k (keys %exclusions) | |||||||||||||||||||||||||||
| 96 | { | ||||||||||||||||||||||||||||
| 97 | 0 | ▶ | next unless exists $opt->{$k}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 0 | foreach my $e (@{ $exclusions{$k} }) | |||||||||||||||||||||||||||
| 99 | { | ||||||||||||||||||||||||||||
| 100 | 0 | ▶ | next unless exists $opt->{$e}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 0 | $self->usage_error("Must not provide both '$k' and '$e' options."); | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if (exists $opt->{dbname} or exists $opt->{database}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $opt->{"dbname"} or exists $opt->{"database"}
MC/DC0%0/2
exists $opt->{"dbname"} or exists $opt->{"database"}
exists $opt->{"dbname"}
exists $opt->{"database"}
Truth table0%0/3
A or B
A= exists $opt->{"dbname"}B= exists $opt->{"database"}
| |||||||||||||||||||||||||||||
| 106 | { | ||||||||||||||||||||||||||||
| 107 | $self->usage_error("'dbname' and 'database' options must be used in conjunction.") | ||||||||||||||||||||||||||||
| 108 | 0 | ▶ | unless exists $opt->{dbname} && exists $opt->{database}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $opt->{"dbname"} and exists $opt->{"database"}
MC/DC0%0/2
exists $opt->{"dbname"} and exists $opt->{"database"}
exists $opt->{"dbname"}
exists $opt->{"database"}
Truth table0%0/3
A and B
A= exists $opt->{"dbname"}B= exists $opt->{"database"}
| |||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | return RDF::Trine::store($opt->{store}) if exists $opt->{store}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | my $dsn = exists $opt->{dbi} | ||||||||||||||||||||||||||||
| 114 | ? $opt->{dbi} | ||||||||||||||||||||||||||||
| 115 | 0 | ▶ | : do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | my ($database, $dbname, $host, $port) = | ||||||||||||||||||||||||||||
| 117 | 0 | map { $opt->{$_} } | |||||||||||||||||||||||||||
| 118 | qw(database dbname host port); | ||||||||||||||||||||||||||||
| 119 | 0 | ▶ | if ($opt->{sqlite}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | { | ||||||||||||||||||||||||||||
| 121 | 0 | $database = 'sqlite'; | |||||||||||||||||||||||||||
| 122 | 0 | $dbname = $opt->{sqlite}; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | my $d; | |||||||||||||||||||||||||||
| 126 | 0 | ▶ | if (lc $database eq 'sqlite') | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 127 | { | ||||||||||||||||||||||||||||
| 128 | 0 | $d = "DBI:SQLite:dbname=${dbname}"; | |||||||||||||||||||||||||||
| 129 | $self->usage_error("SQLite does not support 'host' and 'port'.") | ||||||||||||||||||||||||||||
| 130 | 0 | ▶ | if $opt->{host} || $opt->{port}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opt->{"host"} or $opt->{"port"}
MC/DC0%0/2
$opt->{"host"} or $opt->{"port"}
$opt->{"host"}
$opt->{"port"}
Truth table0%0/3
A or B
A= $opt->{"host"}B= $opt->{"port"}
| |||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | elsif (lc $database eq 'mysql') | ||||||||||||||||||||||||||||
| 133 | { | ||||||||||||||||||||||||||||
| 134 | 0 | $d = "DBI:mysql:database=${dbname}"; | |||||||||||||||||||||||||||
| 135 | 0 | ▶ | $d .= ";host=$host" if $host; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | $d .= ";port=$port" if $port; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | elsif ($database =~ m{^(pg|psql|pgsql|postgres|postgresql)$}i) | ||||||||||||||||||||||||||||
| 139 | { | ||||||||||||||||||||||||||||
| 140 | 0 | $d = "DBI:Pg:dbname=${dbname}"; | |||||||||||||||||||||||||||
| 141 | 0 | ▶ | $d .= ";host=$host" if $host; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 0 | ▶ | $d .= ";port=$port" if $port; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | 0 | $d; | |||||||||||||||||||||||||||
| 145 | }; | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | ▶ | if (length $dsn) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | { | ||||||||||||||||||||||||||||
| 149 | 2 | ▶ | no warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 150 | return RDF::Trine::Store::DBI->new( | ||||||||||||||||||||||||||||
| 151 | "$opt->{model}", | ||||||||||||||||||||||||||||
| 152 | $dsn, | ||||||||||||||||||||||||||||
| 153 | $opt->{username}, | ||||||||||||||||||||||||||||
| 154 | $opt->{password}, | ||||||||||||||||||||||||||||
| 155 | 0 | ); | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | return RDF::Trine::store($ENV{PERLRDF_STORE}) | ||||||||||||||||||||||||||||
| 159 | 0 | ▶ | if defined $ENV{PERLRDF_STORE}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | $self->usage_error("No SQLite, MySQL or Pg database specified."); | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | sub AUTHORITY | ||||||||||||||||||||||||||||
| 165 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
AUTHORITY: not called CC=2 SCAR=11.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 166 | 0 | ▶ | my $class = ref($_[0]) || $_[0]; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $_[0] || $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table0%0/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||||||||||
| 167 | 2 | ▶ | no strict qw(refs); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 168 | 0 | ${"$class\::AUTHORITY"}; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 2 | 1; | |||||||||||||||||||||||||||