detrial
[p5sagit/Object-Tap.git] / lib / Object / Tap.pm
index cb682b1..ce6ddab 100644 (file)
@@ -4,11 +4,15 @@ use strict;
 use warnings;
 use base qw(Exporter);
 
-our $VERSION = '1.000003'; # 1.0.3
+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;
@@ -44,6 +54,11 @@ or use a method name instead of a sub ref -
 
   my $thing = My::Class->new(...)->$_tap(set_foo => 1);
 
+For a 'real' example of how that might be used, one could create and
+initialize an L<HTML::TableExtract> object in one go using -
+
+  my $te = HTML::TableExtract->new->$_tap(parse => $html);
+
 =head1 AUTHOR
 
 mst - Matt S. Trout (cpan:MSTROUT) <mst@shadowcat.co.uk>