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;
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;
is(Foo->$_tap(bar => 'two'), 'Foo', 'invocant returned');
is($tapped, 'Foo two', 'method name tap');
+
+Foo->$_tap(sub { is($_[0], $_, '$_ aliased to object') });