| 1 | package App::perlrdf::Command::StoreTruncate; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | $App::perlrdf::Command::StoreTruncate::AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||
| 10 | 1 | $App::perlrdf::Command::StoreTruncate::VERSION = '0.006'; | |||||||||||||||||||||||||||
| 11 | } | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use App::perlrdf -command; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use constant abstract => q (Delete RDF data from an RDF::Trine::Store.); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use constant command_names => qw( store_truncate truncate ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use constant description => <<'INTRO' . __PACKAGE__->store_help . <<'DESCRIPTION'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | Delete data from an RDF::Trine::Store. | ||||||||||||||||||||||||||||
| 20 | INTRO | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | Note that because multiple stores may share a database, the 'nuke' option | ||||||||||||||||||||||||||||
| 23 | does not currently drop the database; it just removes the table which holds | ||||||||||||||||||||||||||||
| 24 | RDF quads. | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | When one or more graph URIs are specified, the 'nuke' option is ignored, | ||||||||||||||||||||||||||||
| 27 | and prompts are skipped. | ||||||||||||||||||||||||||||
| 28 | DESCRIPTION | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 1 | ▶ | use constant opt_spec => ( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | __PACKAGE__->store_opt_spec, | ||||||||||||||||||||||||||||
| 32 | []=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>, | ||||||||||||||||||||||||||||
| 33 | [ 'graph|g=s@', 'Graph(s) to delete (default: all graphs)' ], | ||||||||||||||||||||||||||||
| 34 | [ 'yes', 'Answer "yes" to prompts' ], | ||||||||||||||||||||||||||||
| 35 | [ 'nuke', 'Delete the entire store' ], | ||||||||||||||||||||||||||||
| 36 | 1 | ); | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | sub execute | ||||||||||||||||||||||||||||
| 39 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 0 | require RDF::Trine; | |||||||||||||||||||||||||||
| 41 | 0 | require App::perlrdf::FileSpec::OutputRDF; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | my ($self, $opt, $arg) = @_; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | my $store = $self->get_store($opt); | |||||||||||||||||||||||||||
| 46 | 0 | my $model = RDF::Trine::Model->new($store); | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if ($opt->{graph}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||
| 50 | 0 | for (@{ $opt->{graph} }) | |||||||||||||||||||||||||||
| 51 | { | ||||||||||||||||||||||||||||
| 52 | 0 | printf STDERR "Truncating graph %s\n", $_; | |||||||||||||||||||||||||||
| 53 | 0 | my $graph = RDF::Trine::Node::Resource->new($_); | |||||||||||||||||||||||||||
| 54 | 0 | $model->remove_statements((undef)x3, $graph); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | printf STDERR "'nuke' ignored when 'graph' specified\n" | ||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if $opt->{nuke}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | else | ||||||||||||||||||||||||||||
| 62 | { | ||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if ($opt->{yes} or prompt_yn("Really delete all data from this store?")) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opt->{"yes"} or prompt_yn("Really delete all data from this store?")
MC/DC0%0/2
$opt->{"yes"} or prompt_yn("Really delete all data from this store?")
$opt->{"yes"}
prompt_yn("Really delete all data from this store?")
Truth table0%0/3
A or B
A= $opt->{"yes"}B= prompt_yn("Really delete all data from this store?")
| |||||||||||||||||||||||||||||
| 64 | { | ||||||||||||||||||||||||||||
| 65 | 0 | $model->remove_statements((undef)x4); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if ($opt->{nuke}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | { | ||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if ($opt->{yes} or prompt_yn("Really nuke this store?")) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opt->{"yes"} or prompt_yn("Really nuke this store?")
MC/DC0%0/2
$opt->{"yes"} or prompt_yn("Really nuke this store?")
$opt->{"yes"}
prompt_yn("Really nuke this store?")
Truth table0%0/3
A or B
A= $opt->{"yes"}B= prompt_yn("Really nuke this store?")
| |||||||||||||||||||||||||||||
| 71 | { | ||||||||||||||||||||||||||||
| 72 | 0 | $store->nuke; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 1 | 1; | |||||||||||||||||||||||||||