X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FObject%2FTap.pm;h=ce6ddab3318d9ea7748d90492e64be3efbaea6ab;hb=1ab69302fcd4c0a358f9146a6744d7f1e8341e41;hp=cecdbd24030fbd8b402328c7c12248097dc26567;hpb=019ed185e20729f373e527f7bb5751b641b707d9;p=p5sagit%2FObject-Tap.git diff --git a/lib/Object/Tap.pm b/lib/Object/Tap.pm index cecdbd2..ce6ddab 100644 --- a/lib/Object/Tap.pm +++ b/lib/Object/Tap.pm @@ -4,11 +4,15 @@ use strict; use warnings; use base qw(Exporter); -our $VERSION = '1.000006'; # TRIAL +our $VERSION = '1.000006'; our @EXPORT = qw($_tap); -our $_tap = sub { my ($obj, $call, @args) = @_; $obj->$call(@args); $obj }; +our $_tap = sub { + my ($obj, $call, @args) = @_; + $obj->$call(@args) for $obj; + $obj +}; 1; @@ -30,6 +34,12 @@ you can instead write - my $thing = My::Class->new(...)->$_tap(sub { $_[0]->set_foo(1) }); +We also alias $_ to $_[0] within the subroutine so: + + my $thing = My::Class->new(...)->$_tap(sub { $_->set_foo(1) }); + +also works. + To realise why this might be useful, consider instead - My::App->new(...)->$_tap(...)->run;