File Coverage

blib/lib/MooseX/CurriedDelegation/Trait/Method/Delegation.pm
Criterion Covered Total %
statement 20 21 95.2
branch 3 6 50.0
condition 1 3 33.3
subroutine 6 6 100.0
pod n/a
total 30 36 83.3


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::Trait::Method::Delegation;
11             our $AUTHORITY = 'cpan:RSRCHBOY';
12             $MooseX::CurriedDelegation::Trait::Method::Delegation::VERSION = '0.003';
13             # ABSTRACT: A trait for curried delegation methods
14              
15 1     1   529 use Moose::Role;
  1         3  
  1         7  
16 1     1   4884 use namespace::autoclean;
  1         2  
  1         8  
17              
18             # debugging...
19             #use Smart::Comments;
20              
21             has curry_coderef => (is => 'ro', isa => 'Coderef', required => 1);
22              
23             # _initialize_body() is largely lifted right from
24             # Moose::Meta::Method::Delegation
25              
26             sub _initialize_body {
27 2     2   1334 my $self = shift;
28              
29 2         11 my $method_to_call = $self->delegate_to_method;
30             # XXX
31             #return $self->{body} = $method_to_call
32             # if ref $method_to_call;
33              
34 2         14 my $accessor = $self->_get_delegate_accessor;
35 2         102 my $handle_name = $self->name;
36              
37             return $self->{body} = sub {
38              
39 4     4   30136 my $instance = shift;
        4      
        4      
40 4         72 my $proxy = $instance->$accessor();
41 4         149 my $curry_coderef = $self->curry_coderef;
42              
43             ### $curry_coderef
44              
45 4 50 33     39 my $error
    50          
46             = !defined $proxy ? ' is not defined'
47             : ref($proxy) && !blessed($proxy) ? qq{ is not an object (got '$proxy')}
48             : undef;
49              
50 4 50       13 if ($error) {
51 0         0 $self->throw_error(
52             "Cannot delegate $handle_name to $method_to_call because "
53             . "the value of "
54             . $self->associated_attribute->name
55             . $error,
56             method_name => $method_to_call,
57             object => $instance
58             );
59             }
60 4         9 unshift @_, @{ $self->curried_arguments };
  4         18  
61 4         36 unshift @_, $instance->$curry_coderef();
62 4         68 $proxy->$method_to_call(@_);
63 2         13 };
64             }
65              
66             !!42;
67              
68             __END__
69              
70             =pod
71              
72             =encoding UTF-8
73              
74             =for :stopwords Chris Weyl
75              
76             =for :stopwords Wishlist flattr flattr'ed gittip gittip'ed
77              
78             =head1 NAME
79              
80             MooseX::CurriedDelegation::Trait::Method::Delegation - A trait for curried delegation methods
81              
82             =head1 VERSION
83              
84             This document describes version 0.003 of MooseX::CurriedDelegation::Trait::Method::Delegation - released November 09, 2016 as part of MooseX-CurriedDelegation.
85              
86             =head1 DESCRIPTION
87              
88             This is just a trait applied to the delegation method metaclass (generally
89             L<Moose::Meta::Method::Delegation>). No user-serviceable parts here.
90              
91             =head1 SEE ALSO
92              
93             Please see those modules/websites for more information related to this module.
94              
95             =over 4
96              
97             =item *
98              
99             L<MooseX::CurriedDelegation|MooseX::CurriedDelegation>
100              
101             =item *
102              
103             L<MooseX::CurriedDelegation>
104              
105             =back
106              
107             =head1 BUGS
108              
109             Please report any bugs or feature requests on the bugtracker website
110             L<https://github.com/RsrchBoy/moosex-currieddelegation/issues>
111              
112             When submitting a bug or request, please include a test-file or a
113             patch to an existing test-file that illustrates the bug or desired
114             feature.
115              
116             =head1 AUTHOR
117              
118             Chris Weyl <cweyl@alumni.drew.edu>
119              
120             =head2 I'm a material boy in a material world
121              
122             =begin html
123              
124             <a href="https://gratipay.com/RsrchBoy/"><img src="http://img.shields.io/gratipay/RsrchBoy.svg" /></a>
125             <a href="http://bit.ly/rsrchboys-wishlist"><img src="http://wps.io/wp-content/uploads/2014/05/amazon_wishlist.resized.png" /></a>
126             <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>
127              
128             =end html
129              
130             Please note B<I do not expect to be gittip'ed or flattr'ed for this work>,
131             rather B<it is simply a very pleasant surprise>. I largely create and release
132             works like this because I need them or I find it enjoyable; however, don't let
133             that stop you if you feel like it ;)
134              
135             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>,
136             L<Gratipay|https://gratipay.com/RsrchBoy/>, or indulge my
137             L<Amazon Wishlist|http://bit.ly/rsrchboys-wishlist>... If and *only* if you so desire.
138              
139             =head1 COPYRIGHT AND LICENSE
140              
141             This software is Copyright (c) 2012 by Chris Weyl.
142              
143             This is free software, licensed under:
144              
145             The GNU Lesser General Public License, Version 2.1, February 1999
146              
147             =cut