Role::Tap - A tiny role for method chaining
package My::Object;
use Role::Tiny::With;
with 'Role::Tap';
# Elsewhere
my $object = My::Object->new->tap($method, @args);
# Longer version
$object = $object->tap(sub { $_->$method(@args) });
# Inject side effects into a method chain
$object->foo('A')->tap(sub { say $_->foo })->foo('B');
Role::Tap is a tiny role based on "tap" in Mojo::Base which gives your object a "tap" method. This method runs a coderef or method on the object, ignores the return value, and returns the object so you can chain more method calls.
$object = $object->tap(sub {...});
$object = $object->tap($method);
$object = $object->tap($method, @args);
K combinator, tap into a method chain to perform operations on an object within the chain. The object will be the first argument passed to the callback and is also available as $_
.
Report any issues on the public bugtracker.
Dan Book <[email protected]>
This software is Copyright (c) 2015 by Dan Book.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
Object::Tap, MooX::ChainedAttributes, MooseX::Attribute::Chained