File Coverage

blib/lib/MooseX/CurriedDelegation.pm
Criterion Covered Total %
statement 14 14 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 21 21 100.0


line stmt bran cond sub pod time code
1             #
2             # This file is part of MooseX-CurriedDelegation
3             #
4             # This software is Copyright (c) 2012 by Chris Weyl.
5             #
6             # This is free software, licensed under:
7             #
8             # The GNU Lesser General Public License, Version 2.1, February 1999
9             #
10             package MooseX::CurriedDelegation;
11             our $AUTHORITY = 'cpan:RSRCHBOY';
12             # git description: 0.002-9-g914914b
13             $MooseX::CurriedDelegation::VERSION = '0.003';
14              
15             # ABSTRACT: Curry your delegations with methods
16              
17 1     1   446567 use strict;
  1         3  
  1         29  
18 1     1   4 use warnings;
  1         3  
  1         25  
19              
20 1     1   4 use Moose ( );
  1         2  
  1         12  
21 1     1   4 use Moose::Exporter;
  1         2  
  1         8  
22              
23             my $trait = 'MooseX::CurriedDelegation::Trait::Attribute';
24              
25             Moose::Exporter->setup_import_methods(
26             trait_aliases => [ [ $trait => 'CurriedDelegation' ] ],
27              
28             as_is => [ qw{ curry_to_self } ],
29             class_metaroles => { attribute => [ $trait ] },
30             role_metaroles => { applied_attribute => [ $trait ] },
31             );
32              
33 2     2 1 6 sub curry_to_self() { sub { shift } }
  1     1   4419  
34              
35             !!42;
36              
37             __END__
38              
39             =pod
40              
41             =encoding UTF-8
42              
43             =for :stopwords Chris Weyl
44              
45             =for :stopwords Wishlist flattr flattr'ed gittip gittip'ed
46              
47             =head1 NAME
48              
49             MooseX::CurriedDelegation - Curry your delegations with methods
50              
51             =head1 VERSION
52              
53             This document describes version 0.003 of MooseX::CurriedDelegation - released November 09, 2016 as part of MooseX-CurriedDelegation.
54              
55             =head1 SYNOPSIS
56              
57             use Moose;
58             use MooseX::CurriedDelegation;
59              
60             has one => (is => 'ro', isa => 'Str', default => 'default');
61              
62             has foo => (
63              
64             is => 'rw',
65             isa => 'TestClass::Delagatee', # has method curried()
66             default => sub { TestClass::Delagatee->new },
67              
68             handles => {
69              
70             # method-curry
71             # Note the hashref, not arrayref, we employ
72             # first arg is the remote method to delegate to
73             # second is an arrayref comprising:
74             # coderef to call as a method on the instance, followed by
75             # "static" curry args
76             #
77             # so, essentially:
78             # $self->foo->remote_method($self->$coderef(), @remaining_args);
79             #
80             # foo_del_one => {
81             # remote_method => [ sub { ... }, qw{ static args } ],
82             # },
83              
84             foo_del_one => { curried => [ sub { shift->one }, qw{ more curry args } ] },
85              
86             # curry_to_self() always returns: sub { shift }
87             foo_del_two => { other_method => [ curry_to_self ] },
88             },
89             );
90              
91             =head1 DESCRIPTION
92              
93             Method delegation is awfully handy -- but sometimes it'd be awfully handier if
94             it was a touch more dynamic. This is an attribute trait that provides for a
95             delegated method to be curried.
96              
97             =head1 USAGE
98              
99             Using this package will cause the relevant attribute trait to be applied
100             without requiring further intervention. We use the standard
101              
102             handles => { local_method => delegate_info, ... }
103              
104             delegation methodology, however our currying is invoked when delegate_info is
105             a hashref. We expect delegate info to look like:
106              
107             { remote_method => [ $coderef, @more_curry_args ] }
108              
109             Only $coderef is ever executed by the delegation. This means that it is safe
110             to have any number of additional coderefs in @more_curry_args: they will be
111             passed through to remote_method without additional manipulation.
112              
113             =head1 ADDITIONAL SUGAR
114              
115             In addition, we export a number of helper functions.
116              
117             =head2 curry_to_self()
118              
119             This function always returns a coderef like "sub { shift }". That is, this:
120              
121             local => { remote => [ curry_to_self ] }
122              
123             is equivalent to:
124              
125             local => { remote => [ sub { shift } ] }
126              
127             is equivalent to:
128              
129             $self->attribute_accessor->remote($self)
130              
131             =head1 TRAIT ALIASES
132              
133             =head2 CurriedDelegation
134              
135             Resolves out to the full name of our attribute trait; you can use it as:
136              
137             has foo => (traits => [CurriedDelegation], ...)
138              
139             =head1 SEE ALSO
140              
141             Please see those modules/websites for more information related to this module.
142              
143             =over 4
144              
145             =item *
146              
147             L<Moose>
148              
149             =item *
150              
151             L<Moose::Meta::Method::Delegation>
152              
153             =back
154              
155             =head1 BUGS
156              
157             Please report any bugs or feature requests on the bugtracker website
158             L<https://github.com/RsrchBoy/moosex-currieddelegation/issues>
159              
160             When submitting a bug or request, please include a test-file or a
161             patch to an existing test-file that illustrates the bug or desired
162             feature.
163              
164             =head1 AUTHOR
165              
166             Chris Weyl <cweyl@alumni.drew.edu>
167              
168             =head2 I'm a material boy in a material world
169              
170             =begin html
171              
172             <a href="https://gratipay.com/RsrchBoy/"><img src="http://img.shields.io/gratipay/RsrchBoy.svg" /></a>
173             <a href="http://bit.ly/rsrchboys-wishlist"><img src="http://wps.io/wp-content/uploads/2014/05/amazon_wishlist.resized.png" /></a>
174             <a href="https://flattr.com/submit/auto?user_id=RsrchBoy&url=https%3A%2F%2Fgithub.com%2FRsrchBoy%2Fmoosex-currieddelegation&title=RsrchBoy's%20CPAN%20MooseX-CurriedDelegation&tags=%22RsrchBoy's%20MooseX-CurriedDelegation%20in%20the%20CPAN%22"><img src="http://api.flattr.com/button/flattr-badge-large.png" /></a>
175              
176             =end html
177              
178             Please note B<I do not expect to be gittip'ed or flattr'ed for this work>,
179             rather B<it is simply a very pleasant surprise>. I largely create and release
180             works like this because I need them or I find it enjoyable; however, don't let
181             that stop you if you feel like it ;)
182              
183             L<Flattr|https://flattr.com/submit/auto?user_id=RsrchBoy&url=https%3A%2F%2Fgithub.com%2FRsrchBoy%2Fmoosex-currieddelegation&title=RsrchBoy's%20CPAN%20MooseX-CurriedDelegation&tags=%22RsrchBoy's%20MooseX-CurriedDelegation%20in%20the%20CPAN%22>,
184             L<Gratipay|https://gratipay.com/RsrchBoy/>, or indulge my
185             L<Amazon Wishlist|http://bit.ly/rsrchboys-wishlist>... If and *only* if you so desire.
186              
187             =head1 COPYRIGHT AND LICENSE
188              
189             This software is Copyright (c) 2012 by Chris Weyl.
190              
191             This is free software, licensed under:
192              
193             The GNU Lesser General Public License, Version 2.1, February 1999
194              
195             =cut