[libcatmandu-perl] 10/85: Adding the each monad
Jonas Smedegaard
dr at jones.dk
Tue May 20 09:56:15 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag 0.91
in repository libcatmandu-perl.
commit 4bb3851b10557a14b6f7b8249277e4b02ba3d56e
Author: Patrick Hochstenbach <patrick.hochstenbach at ugent.be>
Date: Thu May 8 16:41:38 2014 +0200
Adding the each monad
---
lib/Catmandu/Fix/Bind/each.pm | 27 +++++++++++++++++++++++++++
lib/Catmandu/Fix/Bind/identity.pm | 1 -
2 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/lib/Catmandu/Fix/Bind/each.pm b/lib/Catmandu/Fix/Bind/each.pm
new file mode 100644
index 0000000..da37293
--- /dev/null
+++ b/lib/Catmandu/Fix/Bind/each.pm
@@ -0,0 +1,27 @@
+package Catmandu::Fix::Bind::each;
+
+use Moo;
+use Catmandu::Util qw(:data :is);
+use Data::Dumper;
+
+with 'Catmandu::Fix::Bind';
+
+has path => (is => 'ro' , required => 1);
+has index => (is => 'ro');
+
+sub bind {
+ my ($self,$data,$code,$name) = @_;
+
+ my $value = data_at($self->path,$data);
+
+ if (defined $value && is_array_ref($value)) {
+ for my $i (@$value) {
+ $data->{$self->index} = $i if defined $self->index;
+ $data = $code->($data);
+ }
+ }
+
+ $data;
+}
+
+1;
diff --git a/lib/Catmandu/Fix/Bind/identity.pm b/lib/Catmandu/Fix/Bind/identity.pm
index 7972ef3..223cea5 100644
--- a/lib/Catmandu/Fix/Bind/identity.pm
+++ b/lib/Catmandu/Fix/Bind/identity.pm
@@ -1,7 +1,6 @@
package Catmandu::Fix::Bind::identity;
use Moo;
-use Data::Dumper;
with 'Catmandu::Fix::Bind';
--
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