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 115     115   2334 use 5.006;
  115         422  
2 115     115   597 use strict;
  115         235  
  115         2955  
3 115     115   557 use warnings;
  115         240  
  115         42975  
4              
5             package LINQ::Util::Internal;
6              
7             our $AUTHORITY = 'cpan:TOBYINK';
8             our $VERSION = '0.002';
9              
10             sub create_linq {
11 101     101 1 727 require LINQ;
12 101         364 goto \&LINQ::LINQ;
13             }
14              
15             sub throw {
16 49     49 1 17190 require LINQ::Exception;
17 49         156 my $e = shift;
18 49         417 "LINQ::Exception::$e"->throw( @_ );
19             }
20              
21             sub assert_code {
22 988     988 1 1489 my $code = shift;
23            
24 988 100       2553 if ( ref( $code ) eq 'ARRAY' ) {
25 4         10 @_ = @$code;
26 4         8 $code = shift;
27             }
28            
29 988 100       2001 if ( ref( $code ) eq 'Regexp' ) {
30 11 50       32 throw(
31             "CallerError",
32             message => "Regexp cannot accept curried arguments"
33             ) if @_;
34            
35 11         20 my $re = $code;
36 11     35   64 return sub { m/$re/ };
  35         230  
37             }
38            
39 977 100       2070 if ( ref( $code ) ne 'CODE' ) {
40 35         152 require Scalar::Util;
41 35         108 require overload;
42            
43 35 50 33     323 throw(
44             "CallerError",
45             message => "Expected coderef; got '$code'"
46             ) unless Scalar::Util::blessed( $code ) && overload::Method( $code, '&{}' );
47             }
48            
49 977 100       4150 if ( @_ ) {
50 40         85 my @curry = @_;
51 40     127   205 return sub { $code->( @curry, @_ ) };
  127         290  
52             }
53            
54 937         2833 return $code;
55             } #/ sub assert_code
56              
57             1;
58              
59             __END__
60              
61             =pod
62              
63             =encoding utf-8
64              
65             =head1 NAME
66              
67             LINQ::Util::Internal - common functions used internally by LINQ
68              
69             =head1 FUNCTIONS
70              
71             =over
72              
73             =item C<< create_linq( SOURCE ) >>
74              
75             =item C<< throw( EXCEPTION_TYPE, ARGS ) >>
76              
77             =item C<< assert_code( CALLABLE ) >>
78              
79             =back
80              
81             =head1 BUGS
82              
83             Please report any bugs to
84             L<http://rt.cpan.org/Dist/Display.html?Queue=LINQ>.
85              
86             =head1 SEE ALSO
87              
88             L<LINQ>.
89              
90             =head1 AUTHOR
91              
92             Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
93              
94             =head1 COPYRIGHT AND LICENCE
95              
96             This software is copyright (c) 2021 by Toby Inkster.
97              
98             This is free software; you can redistribute it and/or modify it under
99             the same terms as the Perl 5 programming language system itself.
100              
101             =head1 DISCLAIMER OF WARRANTIES
102              
103             THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
104             WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
105             MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.