[libcatmandu-perl] 27/85: Adding support for result method to unwrap monadic values before returning it.

Jonas Smedegaard dr at jones.dk
Tue May 20 09:56:16 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 f4a751d080e93f2e2811b5bc7901c2c56458e83a
Author: Patrick Hochstenbach <patrick.hochstenbach at ugent.be>
Date:   Sun May 11 21:13:39 2014 +0200

    Adding support for result method to unwrap monadic values before
    returning it.
---
 lib/Catmandu/Fix/Bind.pm       |  4 ++++
 lib/Catmandu/Fix/Bind/maybe.pm | 11 ++++++++---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/lib/Catmandu/Fix/Bind.pm b/lib/Catmandu/Fix/Bind.pm
index 3b652b4..c294a82 100644
--- a/lib/Catmandu/Fix/Bind.pm
+++ b/lib/Catmandu/Fix/Bind.pm
@@ -64,6 +64,10 @@ sub emit_bind {
         $perl .= "},'$name',${code_var});"
     }
     
+    if ($self->can('result')) {
+        $perl .= "${unit} = ${bind_var}->result(${unit});";
+    }
+
     if ($self->return) {
         $perl .= "return ${unit};";
     }
diff --git a/lib/Catmandu/Fix/Bind/maybe.pm b/lib/Catmandu/Fix/Bind/maybe.pm
index 2590287..1f5e983 100644
--- a/lib/Catmandu/Fix/Bind/maybe.pm
+++ b/lib/Catmandu/Fix/Bind/maybe.pm
@@ -54,10 +54,10 @@ sub bind {
 	if ($@ && ref $@ eq 'Catmandu::Fix::Reject') {
 		die $@;
 	}
-	else {
+	elsif ($@) {
 		return $self->nothing;
 	}  
-	
+
 	if (defined $res) {
 		return $self->just($res);
 	}
@@ -66,9 +66,14 @@ sub bind {
 	}
 }
 
+sub result {
+	my ($self,$mvar) = @_;
+	$self->value($mvar);
+}
+
 =head1 NAME
 
-Catmandu::Fix::Bind::maybe - a binder that skips fixes is one returns undef
+Catmandu::Fix::Bind::maybe - a binder that skips fixes if one returns undef
 
 =head1 SYNOPSIS
 

-- 
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