package Future::HTTP; use strict; use Filter::signatures; no warnings 'experimental::signatures'; use feature 'signatures'; our $VERSION = '0.12'; our @loops; push @loops, ( ['IO/Async.pm' => 'Future::HTTP::NetAsync' ], ['Mojo/IOLoop.pm' => 'Future::HTTP::Mojo' ], ['AnyEvent.pm' => 'Future::HTTP::AnyEvent'], ['AE.pm' => 'Future::HTTP::AnyEvent'], # POE support would be nice # LWP::UserAgent support would be nice # A threaded backend would also be nice but likely brings in other # interesting problems. How will we load this? We have two prerequisites # now, threads.pm and HTTP::Tiny... #['threads.pm' => 'Future::HTTP::Tiny::threaded' ], ['HTTP/Tiny/Paranoid.pm' => 'Future::HTTP::Tiny::Paranoid'], # The fallback, will always catch due to loading Future::HTTP ['Future/HTTP.pm' => 'Future::HTTP::Tiny'], ); our $implementation; sub new($factoryclass, @args) { $implementation ||= $factoryclass->best_implementation(); # return a new instance $implementation->new(@args); } sub best_implementation( $class, @candidates ) { if(! @candidates) { @candidates = @loops; }; # Find the currently running/loaded event loop(s) #use Data::Dumper; #warn Dumper \%INC; #warn Dumper \@candidates; my @applicable_implementations = map { $_->[1] } grep { $INC{$_->[0]} } @candidates; # Check which one we can load: for my $impl (@applicable_implementations) { if( eval "require $impl; 1" ) { return $impl; }; }; };