Fix POD typo: sub name -> sub ref
[p5sagit/Object-Tap.git] / lib / Object / Tap.pm
CommitLineData
9e15d0fb 1package Object::Tap;
2
3use strict;
4use warnings;
5use base qw(Exporter);
6
4fb7e663 7our $VERSION = '1.000003'; # 1.0.3
9e15d0fb 8
9our @EXPORT = qw($_tap);
10
11our $_tap = sub { my ($obj, $call, @args) = @_; $obj->$call(@args); $obj };
12
131;
14
15=head1 NAME
16
17Object::Tap - Tap into a series of method calls to alter an object
18
19=head1 SYNOPSIS
20
21Instead of writing -
22
23 my $thing = My::Class->new(...);
24
25 $thing->set_foo(1);
26
27you can instead write -
28
29 use Object::Tap;
30
31 my $thing = My::Class->new(...)->$_tap(sub { $_[0]->set_foo(1) });
32
33To realise why this might be useful, consider instead -
34
35 My::App->new(...)->$_tap(...)->run;
36
37where a variable is thereby not required at all.
38
39You can also pass extra args -
40
41 $obj->$_tap(sub { warn "Got arg: $_[1]" }, 'arg');
42
f72e0060 43or use a method name instead of a sub ref -
9e15d0fb 44
45 my $thing = My::Class->new(...)->$_tap(set_foo => 1);
46
47=head1 AUTHOR
48
49mst - Matt S. Trout (cpan:MSTROUT) <mst@shadowcat.co.uk>
50
51=head1 CONTRIBUTORS
52
53None yet. Well volunteered? :)
54
55=head1 COPYRIGHT
56
57Copyright (c) 2014 the Object::Tap L</AUTHOR> and L</CONTRIBUTORS>
58as listed above.
59
60=head1 LICENSE
61
62This library is free software and may be distributed under the same terms
63as perl itself.
64
65=cut