7 our $VERSION = '1.000003'; # 1.0.3
9 our @EXPORT = qw($_tap);
11 our $_tap = sub { my ($obj, $call, @args) = @_; $obj->$call(@args); $obj };
17 Object::Tap - Tap into a series of method calls to alter an object
23 my $thing = My::Class->new(...);
27 you can instead write -
31 my $thing = My::Class->new(...)->$_tap(sub { $_[0]->set_foo(1) });
33 To realise why this might be useful, consider instead -
35 My::App->new(...)->$_tap(...)->run;
37 where a variable is thereby not required at all.
39 You can also pass extra args -
41 $obj->$_tap(sub { warn "Got arg: $_[1]" }, 'arg');
43 or use a method name instead of a sub ref -
45 my $thing = My::Class->new(...)->$_tap(set_foo => 1);
47 For a 'real' example of how that might be used, one could create and
48 initialize an L<HTML::TableExtract> object in one go using -
50 my $te = HTML::TableExtract->new->$_tap(parse => $html);
54 mst - Matt S. Trout (cpan:MSTROUT) <mst@shadowcat.co.uk>
58 None yet. Well volunteered? :)
62 Copyright (c) 2014 the Object::Tap L</AUTHOR> and L</CONTRIBUTORS>
67 This library is free software and may be distributed under the same terms