File Coverage

blib/lib/Future/XS.pm
Criterion Covered Total %
statement 22 28 78.5
branch 2 4 50.0
condition n/a
subroutine 7 7 100.0
pod n/a
total 31 39 79.4


line stmt bran cond sub pod time code
1             # You may distribute under the terms of either the GNU General Public License
2             # or the Artistic License (the same terms as Perl itself)
3             #
4             # (C) Paul Evans, 2022 -- leonerd@leonerd.org.uk
5              
6             package Future::XS 0.08;
7              
8 2     2   70074 use v5.14;
  2         13  
9 2     2   9 use warnings;
  2         4  
  2         48  
10              
11 2     2   8 use Carp;
  2         4  
  2         170  
12              
13             require XSLoader;
14             XSLoader::load( __PACKAGE__, our $VERSION );
15              
16 2     2   1198 use Time::HiRes qw( tv_interval );
  2         2833  
  2         8  
17              
18             # Future::_base is provided in Future.pm itself
19             require Future;
20             our @ISA = qw( Future::_base );
21              
22             require Future::Exception;
23              
24             =head1 NAME
25              
26             C - experimental XS implementation of C
27              
28             =head1 SYNOPSIS
29              
30             my $future = Future::XS->new;
31              
32             perform_some_operation(
33             on_complete => sub {
34             $future->done( @_ );
35             }
36             );
37              
38             $future->on_ready( sub {
39             say "The operation is complete";
40             } );
41              
42             =head1 DESCRIPTION
43              
44             This module provides an XS-based implementation of the L class. It is
45             currently experimental and shipped in its own distribution for testing
46             purposes, though once it seems stable the plan is to move it into the main
47             C distribution and load it automatically in favour of the pureperl
48             implementation on supported systems.
49              
50             =cut
51              
52             sub import
53             {
54 2     2   15 my $pkg = shift;
55 2         4 my $caller = caller;
56              
57 2         4 my %syms = map { $_ => 1 } @_;
  0         0  
58              
59 2 50       9 if( delete $syms{"-default"} ) {
60 0         0 require Future;
61              
62 2     2   580 no warnings 'redefine';
  2         3  
  2         145  
63 0         0 foreach my $name (qw( new done fail )) {
64 2     2   13 no strict 'refs';
  2         5  
  2         311  
65 0         0 *{"Future::${name}"} = \&{__PACKAGE__."::${name}"};
  0         0  
  0         0  
66             }
67             }
68              
69 2 50       74 croak "Unrecognised $pkg\->import symbols - " . join( ", ", sort keys %syms )
70             if %syms;
71             }
72              
73             =head1 AUTHOR
74              
75             Paul Evans
76              
77             =cut
78              
79             0x55AA;