bump version to 1.000005
[p5sagit/Object-Tap.git] / lib / Object / Tap.pm
CommitLineData
9e15d0fb 1package Object::Tap;
2
3use strict;
4use warnings;
5use base qw(Exporter);
6
c9c985cf 7our $VERSION = '1.000005';
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
96021ef6 47For a 'real' example of how that might be used, one could create and
48initialize an L<HTML::TableExtract> object in one go using -
49
50 my $te = HTML::TableExtract->new->$_tap(parse => $html);
51
9e15d0fb 52=head1 AUTHOR
53
54mst - Matt S. Trout (cpan:MSTROUT) <mst@shadowcat.co.uk>
55
56=head1 CONTRIBUTORS
57
58None yet. Well volunteered? :)
59
60=head1 COPYRIGHT
61
62Copyright (c) 2014 the Object::Tap L</AUTHOR> and L</CONTRIBUTORS>
63as listed above.
64
65=head1 LICENSE
66
67This library is free software and may be distributed under the same terms
68as perl itself.
69
70=cut