| 1 | package Net::Curl::Promiser::LoopBase; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | =encoding utf-8 | ||
| 7 | |||
| 8 | =head1 NAME | ||
| 9 | |||
| 10 | Net::Curl::Promiser::LoopBase - base class for event-loop-based implementations | ||
| 11 | |||
| 12 | =head1 INVALID METHODS | ||
| 13 | |||
| 14 | The following methods from L<Net::Curl::Promiser> are unneeded in instances | ||
| 15 | of this class and thus produce an exception if called: | ||
| 16 | |||
| 17 | =over | ||
| 18 | |||
| 19 | =item C<process()> | ||
| 20 | |||
| 21 | =item C<time_out()> | ||
| 22 | |||
| 23 | =item C<get_timeout()> | ||
| 24 | |||
| 25 | =back | ||
| 26 | |||
| 27 | =head1 TODO | ||
| 28 | |||
| 29 | This is a rather hacky way accomplish this. Refactor it to be more-better. | ||
| 30 | |||
| 31 | Also incorporate the copy-pasted timeout logic from subclasses. | ||
| 32 | |||
| 33 | =cut | ||
| 34 | |||
| 35 | #---------------------------------------------------------------------- | ||
| 36 | |||
| 37 | use parent qw( Net::Curl::Promiser ); | ||
| 38 | |||
| 39 | use Net::Curl (); | ||
| 40 | |||
| 41 | # In production there’s probably little reason to care about this, | ||
| 42 | # but it might be useful for debugging. | ||
| 43 | use constant _STRICT_STOP_POLL => 0; | ||
| 44 | |||
| 45 | #---------------------------------------------------------------------- | ||
| 46 | |||
| 47 | *_process_in_loop = __PACKAGE__->can('SUPER::process'); | ||
| 48 | *_time_out_in_loop = __PACKAGE__->can('SUPER::time_out'); | ||
| 49 | |||
| 50 | # 7.66 is observed not to have this problem; | ||
| 51 | # assumedly newer libcurls won’t regress. | ||
| 52 | use constant _MINIMUM_LIBCURL_TO_WARN_ABOUT_EXTRA_STOP_POLL => 7.52; | ||
| 53 | |||
| 54 | sub process { die 'Unneeded method: ' . (caller 0)[3] }; | ||
| 55 | sub get_timeout { die 'Unneeded method: ' . (caller 0)[3] }; | ||
| 56 | sub time_out { die 'Unneeded method: ' . (caller 0)[3] }; | ||
| 57 | |||
| 58 | sub _GET_FD_ACTION { | ||
| 59 | return +{ @{ $_[1] } }; | ||
| 60 | } | ||
| 61 | |||
| 62 | sub _handle_extra_stop_poll { | ||
| 63 | my ($self, $fd) = @_; | ||
| 64 | |||
| 65 | if (_STRICT_STOP_POLL) { | ||
| 66 | my $version = Net::Curl::LIBCURL_VERSION(); | ||
| 67 | |||
| 68 | if ( $version =~ m<\A([0-9]+\.[0-9]+)> ) { | ||
| 69 | if ($1 >= _MINIMUM_LIBCURL_TO_WARN_ABOUT_EXTRA_STOP_POLL) { | ||
| 70 | my $ref = ref $self; | ||
| 71 | warn "$ref: Unexpected “extra” FD stop (libcurl $version): [$fd]"; | ||
| 72 | } | ||
| 73 | } | ||
| 74 | else { | ||
| 75 | warn "Unparseable LIBCURL_VERSION: [$version]"; | ||
| 76 | } | ||
| 77 | } | ||
| 78 | |||
| 79 | return; | ||
| 80 | } | ||
| 81 | |||
| 82 | 1; |