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