[libcatmandu-perl] 48/101: Droppable, Transactional interfaces
Jonas Smedegaard
dr at jones.dk
Tue Feb 23 13:43:52 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository libcatmandu-perl.
commit e8a5e92dab15513453bcaf5d00028a110b6a9457
Author: Nicolas Steenlant <nicolas.steenlant at ugent.be>
Date: Mon Jan 18 13:52:50 2016 +0100
Droppable, Transactional interfaces
---
lib/Catmandu/Bag.pm | 5 -----
lib/Catmandu/Cmd/drop.pm | 5 +++--
lib/Catmandu/Droppable.pm | 36 ++++++++++++++++++++++++++++++++++++
lib/Catmandu/Searchable.pm | 2 +-
lib/Catmandu/Store.pm | 6 ------
lib/Catmandu/Store/Hash.pm | 1 +
lib/Catmandu/Store/Hash/Bag.pm | 1 +
lib/Catmandu/Transactional.pm | 40 ++++++++++++++++++++++++++++++++++++++++
8 files changed, 82 insertions(+), 14 deletions(-)
diff --git a/lib/Catmandu/Bag.pm b/lib/Catmandu/Bag.pm
index cad06b8..2970b3a 100644
--- a/lib/Catmandu/Bag.pm
+++ b/lib/Catmandu/Bag.pm
@@ -17,7 +17,6 @@ with 'Catmandu::Addable';
requires 'get';
requires 'delete';
requires 'delete_all';
-requires 'drop';
has store => (is => 'ro');
has name => (is => 'ro');
@@ -184,10 +183,6 @@ Clear the bag.
Commit changes.
-=head2 drop
-
-Delete the bag.
-
=head2 log
Return the current logger.
diff --git a/lib/Catmandu/Cmd/drop.pm b/lib/Catmandu/Cmd/drop.pm
index 92dfb03..89dbefb 100644
--- a/lib/Catmandu/Cmd/drop.pm
+++ b/lib/Catmandu/Cmd/drop.pm
@@ -6,6 +6,7 @@ our $VERSION = '0.9505';
use parent 'Catmandu::Cmd';
use Catmandu;
+use Catmandu::Util qw(check_able);
use namespace::clean;
sub command_opt_spec {
@@ -21,9 +22,9 @@ sub command {
my $from = Catmandu->store($from_args->[0], $from_opts);
if ($opts->bag) {
- $from->bag($opts->bag)->drop;
+ check_able($from->bag($opts->bag), 'drop')->drop;
} else {
- $from->drop;
+ check_able($from, 'drop')->drop;
}
}
diff --git a/lib/Catmandu/Droppable.pm b/lib/Catmandu/Droppable.pm
new file mode 100644
index 0000000..a5d4b4c
--- /dev/null
+++ b/lib/Catmandu/Droppable.pm
@@ -0,0 +1,36 @@
+package Catmandu::Droppable;
+
+use Catmandu::Sane;
+
+our $VERSION = '0.9505';
+
+use Moo::Role;
+use namespace::clean;
+
+requires 'drop';
+
+1;
+
+__END__
+
+=pod
+
+=head1 NAME
+
+Catmandu::Droppable - Optional role for droppable stores or bags
+
+=head1 SYNOPSIS
+
+ # delete a store
+ $store->drop;
+ # delete a single bag
+ $store->bag('sessions')->drop;
+
+=head1 METHODS
+
+=head2 drop
+
+Drop the store or bag.
+
+=cut
+
diff --git a/lib/Catmandu/Searchable.pm b/lib/Catmandu/Searchable.pm
index 75e1992..a269984 100644
--- a/lib/Catmandu/Searchable.pm
+++ b/lib/Catmandu/Searchable.pm
@@ -65,7 +65,7 @@ __END__
=head1 NAME
-Catmandu::Searchable - Base class for all searchable Catmandu classes
+Catmandu::Searchable - Optional role for searchable stores
=head1 SYNOPSIS
diff --git a/lib/Catmandu/Store.pm b/lib/Catmandu/Store.pm
index 1d4d0f9..7d23d2c 100644
--- a/lib/Catmandu/Store.pm
+++ b/lib/Catmandu/Store.pm
@@ -9,8 +9,6 @@ use Sub::Quote qw(quote_sub);
use Moo::Role;
use namespace::clean;
-requires 'drop';
-
with 'Catmandu::Logger';
has bag_class => (
@@ -132,10 +130,6 @@ provided for each $bagname using the 'bags' parameter. E.g.
Create or retieve a bag with name $name. Returns a L<Catmandu::Bag>.
-=head2 drop
-
-Delete the store and all it's bags.
-
=head2 log
Return the current logger. Can be used when creating your own Stores.
diff --git a/lib/Catmandu/Store/Hash.pm b/lib/Catmandu/Store/Hash.pm
index dfe73ef..1e5cb53 100644
--- a/lib/Catmandu/Store/Hash.pm
+++ b/lib/Catmandu/Store/Hash.pm
@@ -10,6 +10,7 @@ use Catmandu::Store::Hash::Bag;
use namespace::clean;
with 'Catmandu::Store';
+with 'Catmandu::Droppable';
has _hashes => (is => 'ro' , lazy => 1, init_arg => undef, default => sub { +{} });
has init_data => (is => 'ro');
diff --git a/lib/Catmandu/Store/Hash/Bag.pm b/lib/Catmandu/Store/Hash/Bag.pm
index f096224..00d5a61 100644
--- a/lib/Catmandu/Store/Hash/Bag.pm
+++ b/lib/Catmandu/Store/Hash/Bag.pm
@@ -10,6 +10,7 @@ use Clone qw(clone);
use namespace::clean;
with 'Catmandu::Bag';
+with 'Catmandu::Droppable';
has _hash => (is => 'rw', lazy => 1 , init_arg => undef, builder => '_build_hash');
has _head => (is => 'rw', init_arg => undef, clearer => '_clear_head');
diff --git a/lib/Catmandu/Transactional.pm b/lib/Catmandu/Transactional.pm
new file mode 100644
index 0000000..d4659e0
--- /dev/null
+++ b/lib/Catmandu/Transactional.pm
@@ -0,0 +1,40 @@
+package Catmandu::Transactional;
+
+use Catmandu::Sane;
+
+our $VERSION = '0.9505';
+
+use Moo::Role;
+use namespace::clean;
+
+requires 'transaction';
+
+1;
+
+__END__
+
+=pod
+
+=head1 NAME
+
+Catmandu::Transactional - Optional role for transactional stores
+
+=head1 SYNOPSIS
+
+ # bag will be untouched
+ my $store->transaction(sub {
+ $store->bag('books')->add({title => 'Time must have a stop'});
+ die;
+ });
+
+=head1 METHODS
+
+=head2 transaction($sub)
+
+C<transaction> takes a coderef that will be executed in the context of a
+transaction. If an error is thrown, the transaction will rollback. If the code
+executes successfully, the transaction will be committed. There is no support
+for nested transactions, nested calls to C<transaction> will simply be subsumed
+by their parent transaction.
+
+=cut
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcatmandu-perl.git
More information about the Pkg-perl-cvs-commits
mailing list