File Coverage

blib/lib/LINQ/Util/Internal.pm
Criterion Covered Total %
statement 31 31 100.0
branch 10 12 83.3
condition 1 3 33.3
subroutine 8 8 100.0
pod 3 3 100.0
total 53 57 92.9


line stmt bran cond sub pod time code
1 116     116   2059 use 5.006;
  116         427  
2 116     116   621 use strict;
  116         243  
  116         2869  
3 116     116   575 use warnings;
  116         221  
  116         42956  
4              
5              
6             our $AUTHORITY = 'cpan:TOBYINK';
7             our $VERSION = '0.003';
8              
9             require LINQ;
10             goto \&LINQ::LINQ;
11 103     103 1 776 }
12 103         378  
13             require LINQ::Exception;
14             my $e = shift;
15             "LINQ::Exception::$e"->throw( @_ );
16 49     49 1 16355 }
17 49         154  
18 49         404 my $code = shift;
19            
20             if ( ref( $code ) eq 'ARRAY' ) {
21             @_ = @$code;
22 1002     1002 1 1477 $code = shift;
23             }
24 1002 100       2367
25 4         10 if ( ref( $code ) eq 'Regexp' ) {
26 4         6 throw(
27             "CallerError",
28             message => "Regexp cannot accept curried arguments"
29 1002 100       1980 ) if @_;
30 11 50       32
31             my $re = $code;
32             return sub { m/$re/ };
33             }
34            
35 11         18 if ( ref( $code ) ne 'CODE' ) {
36 11     35   53 require Scalar::Util;
  35         266  
37             require overload;
38            
39 991 100       2045 throw(
40 39         162 "CallerError",
41 39         124 message => "Expected coderef; got '$code'"
42             ) unless Scalar::Util::blessed( $code ) && overload::Method( $code, '&{}' );
43 39 50 33     245 }
44            
45             if ( @_ ) {
46             my @curry = @_;
47             return sub { $code->( @curry, @_ ) };
48             }
49 991 100       4090
50 40         91 return $code;
51 40     127   203 } #/ sub assert_code
  127         294  
52              
53             1;
54 951         2858  
55              
56             =pod
57              
58             =encoding utf-8
59              
60             =head1 NAME
61              
62             LINQ::Util::Internal - common functions used internally by LINQ
63              
64             =head1 FUNCTIONS
65              
66             =over
67              
68             =item C<< create_linq( SOURCE ) >>
69              
70             =item C<< throw( EXCEPTION_TYPE, ARGS ) >>
71              
72             =item C<< assert_code( CALLABLE ) >>
73              
74             =back
75              
76             =head1 BUGS
77              
78             Please report any bugs to
79             L<http://rt.cpan.org/Dist/Display.html?Queue=LINQ>.
80              
81             =head1 SEE ALSO
82              
83             L<LINQ>.
84              
85             =head1 AUTHOR
86              
87             Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
88              
89             =head1 COPYRIGHT AND LICENCE
90              
91             This software is copyright (c) 2021 by Toby Inkster.
92              
93             This is free software; you can redistribute it and/or modify it under
94             the same terms as the Perl 5 programming language system itself.
95              
96             =head1 DISCLAIMER OF WARRANTIES
97              
98             THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
99             WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
100             MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.