[libcatmandu-perl] 53/85: Fixing documentation for Binds

Jonas Smedegaard dr at jones.dk
Tue May 20 09:56:19 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 d7842ccba32a32857396f76001247b92a2952823
Author: Patrick Hochstenbach <patrick.hochstenbach at ugent.be>
Date:   Fri May 16 10:33:32 2014 +0200

    Fixing documentation for Binds
---
 lib/Catmandu/Fix.pm                | 10 +++-------
 lib/Catmandu/Fix/Bind.pm           | 15 +++++++--------
 lib/Catmandu/Fix/Bind/benchmark.pm |  2 +-
 lib/Catmandu/Fix/Bind/identity.pm  |  2 +-
 lib/Catmandu/Fix/Bind/list.pm      |  2 +-
 lib/Catmandu/Fix/Bind/maybe.pm     |  2 +-
 6 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/lib/Catmandu/Fix.pm b/lib/Catmandu/Fix.pm
index de5277d..72c9652 100644
--- a/lib/Catmandu/Fix.pm
+++ b/lib/Catmandu/Fix.pm
@@ -1,7 +1,3 @@
-package Catmandu::Fix::Reject;
-
-use Moo;
-
 package Catmandu::Fix;
 
 use Catmandu::Sane;
@@ -29,7 +25,7 @@ has _num_vars   => (is => 'rw', lazy => 1, init_arg => undef, default => sub { 0
 has _captures   => (is => 'ro', lazy => 1, init_arg => undef, default => sub { +{}; });
 has var         => (is => 'ro', lazy => 1, init_arg => undef, builder => 'generate_var');
 has fixes       => (is => 'ro', required => 1, trigger => 1);
-has _reject     => (is => 'ro', init_arg => undef, default => sub { Catmandu::Fix::Reject->new; });
+has _reject     => (is => 'ro', init_arg => undef, default => sub { +{}; });
 has _reject_var => (is => 'ro', lazy => 1, init_arg => undef, builder => '_build_reject_var');
 
 sub _build_parser {
@@ -124,7 +120,7 @@ sub emit {
     $perl .= $self->emit_fixes($self->fixes);
 
     $perl .= "return ${var};";
-    $perl .= "__REJECT__: return ${reject_var};";
+    $perl .= "__FIX_REJECT__: return ${reject_var};";
     $perl .= "} or do {";
     $perl .= $self->emit_declare_vars($err, '$@');
     # TODO throw Catmandu::Error
@@ -181,7 +177,7 @@ sub emit_fixes {
 sub emit_reject {
     my ($self) = @_;
     my $reject_var = $self->_reject_var;
-    "goto __REJECT__;";
+    "goto __FIX_REJECT__;";
 }
 
 sub emit_fix {
diff --git a/lib/Catmandu/Fix/Bind.pm b/lib/Catmandu/Fix/Bind.pm
index 88213b3..aec21f1 100644
--- a/lib/Catmandu/Fix/Bind.pm
+++ b/lib/Catmandu/Fix/Bind.pm
@@ -55,12 +55,11 @@ sub emit_bind {
     for my $pair (@$code) { 
         my $name = $pair->[0];
         my $code = $pair->[1]; 
-        my $code_var = $fixer->capture($code);
         $perl .= "${unit} = ${bind_var}->bind(${unit}, sub {";
         $perl .= "my ${var} = shift;";
         $perl .= $code;
         $perl .= "${var}";
-        $perl .= "},'$name',${code_var});"
+        $perl .= "},'$name');"
     }
     
     if ($self->can('result')) {
@@ -170,8 +169,8 @@ of 'unit' is:
 =head2 bind($wrapped_data,$code,$name,$perl)
 
 The bind method is executed for every Catmandu::Fix method in the fix script. It receives the $wrapped_data
-(wrapped by 'unit'), the fix method as anonymous subroutine, the name of the fix and the actual perl
-code which runs it as a string. It should return data with the same type as returned by 'unit'. 
+(wrapped by 'unit'), the fix method as anonymous subroutine and the name of the fix. It should return data 
+with the same type as returned by 'unit'. 
 A trivial, but verbose, implementaion of 'bind' is:
 
   sub bind {
@@ -191,8 +190,8 @@ in 3  monadic laws:
 
    my $monad = Catmandu::Fix::Bind->demo();
 
-   # bind(unit(data), coderef) == coderef(data)
-   $monad->bind( $monad->unit({foo=>'bar'}) , $coderef) == $coderef->({foo=>'bar'});
+   # bind(unit(data), coderef) == unit(coderef(data))
+   $monad->bind( $monad->unit({foo=>'bar'}) , $coderef) == $monad->unit($coderef->({foo=>'bar'}));
 
 =head2 right unit: unit act as a neutral element of bind
 
@@ -201,12 +200,12 @@ in 3  monadic laws:
 
 =head2 associative: chaining bind blocks should have the same effect as nesting them
 
-   # bind(bind(unit(data),f),g) == bind(unit(data), sub { return bind(f(data),g) } )
+   # bind(bind(unit(data),f),g) == bind(unit(data), sub { return bind(unit(f(data)),g) } )
    my $f = sub { my $data = shift; $data->{demo} = 1 ; $data };
    my $g = sub { my $data = shift; $data->{demo} += 1 ; $data};
 
    $monad->bind( $monad->bind( $monad->unit({}) , f ) , g ) ==
-     $monad->bind( $monad->unit({}) , sub { my $data = shift; $monad->bind($f->($data), $g ); $data; });
+     $monad->bind( $monad->unit({}) , sub { my $data = shift; $monad->bind($monad->unit($f->($data)), $g ); $data; });
 
 =head1 SEE ALSO
 
diff --git a/lib/Catmandu/Fix/Bind/benchmark.pm b/lib/Catmandu/Fix/Bind/benchmark.pm
index c82539b..d4a3e04 100644
--- a/lib/Catmandu/Fix/Bind/benchmark.pm
+++ b/lib/Catmandu/Fix/Bind/benchmark.pm
@@ -80,7 +80,7 @@ Required. The path of a file to which the benchmark statistics will be written.
 
 =head1 AUTHOR
 
-Patrick Hochstenbach <Patrick . Hochstenbach @ UGent . be >
+Patrick Hochstenbach - L<Patrick.Hochstenbach at UGent.be>
 
 =head1 SEE ALSO
 
diff --git a/lib/Catmandu/Fix/Bind/identity.pm b/lib/Catmandu/Fix/Bind/identity.pm
index e50e480..aa06591 100644
--- a/lib/Catmandu/Fix/Bind/identity.pm
+++ b/lib/Catmandu/Fix/Bind/identity.pm
@@ -37,7 +37,7 @@ applies the bound fix functions to its input without any modification.
 
 =head1 AUTHOR
 
-Patrick Hochstenbach <Patrick . Hochstenbach @ UGent . be >
+Patrick Hochstenbach - L<Patrick.Hochstenbach at UGent.be>
 
 =head1 SEE ALSO
 
diff --git a/lib/Catmandu/Fix/Bind/list.pm b/lib/Catmandu/Fix/Bind/list.pm
index 4793270..65be6cf 100644
--- a/lib/Catmandu/Fix/Bind/list.pm
+++ b/lib/Catmandu/Fix/Bind/list.pm
@@ -75,7 +75,7 @@ The path to a list in the data.
 
 =head1 AUTHOR
 
-Patrick Hochstenbach <Patrick . Hochstenbach @ UGent . be >
+Patrick Hochstenbach - L<Patrick.Hochstenbach at UGent.be>
 
 =head1 SEE ALSO
 
diff --git a/lib/Catmandu/Fix/Bind/maybe.pm b/lib/Catmandu/Fix/Bind/maybe.pm
index 7e3c3a2..d1afab5 100644
--- a/lib/Catmandu/Fix/Bind/maybe.pm
+++ b/lib/Catmandu/Fix/Bind/maybe.pm
@@ -89,7 +89,7 @@ The maybe binder computes all the Fix function and ignores fixes that throw exce
 
 =head1 AUTHOR
 
-Patrick Hochstenbach <Patrick . Hochstenbach @ UGent . be >
+Patrick Hochstenbach - L<Patrick.Hochstenbach at UGent.be>
 
 =head1 SEE ALSO
 

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