File Coverage

blib/lib/Perinci/Sub/Property/curry.pm
Criterion Covered Total %
statement 22 22 100.0
branch n/a
condition 2 5 40.0
subroutine 6 6 100.0
pod n/a
total 30 33 90.9


line stmt bran cond sub pod time code
1             package Perinci::Sub::Property::curry;
2              
3             our $DATE = '2016-05-12'; # DATE
4             our $VERSION = '0.07'; # VERSION
5              
6 1     1   8928 use 5.010001;
  1         4  
7 1     1   5 use strict;
  1         5  
  1         20  
8 1     1   4 use warnings;
  1         2  
  1         38  
9             #use Log::Any '$log';
10              
11 1     1   6 use Data::Dmp;
  1         2  
  1         61  
12 1     1   490 use Perinci::Sub::PropertyUtil qw(declare_property);
  1         1046  
  1         195  
13              
14             declare_property(
15             name => 'curry',
16             type => 'function',
17             schema => ['hash*'],
18             wrapper => {
19             meta => {
20             v => 2,
21             prio => 10,
22             convert => 1,
23             },
24             handler => sub {
25 6     6   53588 my ($self, %args) = @_;
26 6   33     39 my $v = $args{new} // $args{value} // {};
      50        
27 6         10 my $meta = $args{meta};
28              
29 6         18 $self->select_section('before_call_arg_validation');
30 6         86 for my $an (keys %$v) {
31 6         12 my $av = $v->{$an};
32 6         28 $self->_errif(400, "\"Argument $an has been set by curry\"",
33             'exists($args{\''.$an.'\'})');
34 6         527 $self->push_lines(
35             '$args{\''.$an.'\'} = '.dmp($av).';');
36             }
37             },
38             },
39             );
40              
41             1;
42             # ABSTRACT: Set arguments for function
43              
44             __END__
45              
46             =pod
47              
48             =encoding UTF-8
49              
50             =head1 NAME
51              
52             Perinci::Sub::Property::curry - Set arguments for function
53              
54             =head1 VERSION
55              
56             This document describes version 0.07 of Perinci::Sub::Property::curry (from Perl distribution Perinci-Sub-Property-curry), released on 2016-05-12.
57              
58             =head1 SYNOPSIS
59              
60             # in function metadata
61             args => {a=>{}, b=>{}, c=>{}},
62             curry => {a=>10},
63              
64             # when calling function
65             f(); # equivalent to f(a=>10)
66             f(b=>20, c=>30); # equivalent to f(a=>10, b=>20, c=>30)
67             f(a=>5, b=>20); # error, a has been set by curry
68              
69             =head1 DESCRIPTION
70              
71             This property sets arguments for function.
72              
73             =head1 HOMEPAGE
74              
75             Please visit the project's homepage at L<https://metacpan.org/release/Perinci-Sub-Property-curry>.
76              
77             =head1 SOURCE
78              
79             Source repository is at L<https://github.com/perlancar/perl-Perinci-Sub-Property-curry>.
80              
81             =head1 BUGS
82              
83             Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Perinci-Sub-Property-curry>
84              
85             When submitting a bug or request, please include a test-file or a
86             patch to an existing test-file that illustrates the bug or desired
87             feature.
88              
89             =head1 SEE ALSO
90              
91             L<Perinci>
92              
93             =head1 AUTHOR
94              
95             perlancar <perlancar@cpan.org>
96              
97             =head1 COPYRIGHT AND LICENSE
98              
99             This software is copyright (c) 2016 by perlancar@cpan.org.
100              
101             This is free software; you can redistribute it and/or modify it under
102             the same terms as the Perl 5 programming language system itself.
103              
104             =cut