| 1 | 25 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 25 | ▶ | BEGIN { # do the right thing for threads? | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 4 | 25 | ▶ | eval { require attrs; } or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 5 | 25 | $INC{'attrs.pm'} = ""; | |||||||||||||||||||||||||||
| 6 | 25 | ▶ | *attrs::import = sub {}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | } | ||||||||||||||||||||||||||||
| 8 | } | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | package Event; | ||||||||||||||||||||||||||||
| 11 | 25 | require 5.008; | |||||||||||||||||||||||||||
| 12 | 25 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 25 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 25 | eval { require Carp::Heavy; }; # work around perl_call_pv bug XXX | |||||||||||||||||||||||||||
| 15 | 25 | our $API; | |||||||||||||||||||||||||||
| 16 | 25 | our $VERSION = '1.29'; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # If we inherit DynaLoader then we inherit AutoLoader; Bletch! | ||||||||||||||||||||||||||||
| 19 | 25 | require DynaLoader; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # DynaLoader calls dl_load_flags as a static method. | ||||||||||||||||||||||||||||
| 22 | 25 | *dl_load_flags = DynaLoader->can('dl_load_flags'); | |||||||||||||||||||||||||||
| 23 | 25 | ▶ | (defined(&bootstrap)? \&bootstrap : \&DynaLoader::bootstrap)-> | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | (__PACKAGE__, $VERSION); | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 25 | our $DebugLevel = 0; | |||||||||||||||||||||||||||
| 27 | 25 | our $Eval = 0; # avoid because c_callback is exempt | |||||||||||||||||||||||||||
| 28 | 25 | our $DIED = \&default_exception_handler; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 25 | our @EXPORT_OK = qw(time all_events all_watchers all_running all_queued all_idle | |||||||||||||||||||||||||||
| 31 | one_event sweep loop unloop unloop_all sleep queue | ||||||||||||||||||||||||||||
| 32 | queue_pending | ||||||||||||||||||||||||||||
| 33 | QUEUES PRIO_NORMAL PRIO_HIGH NO_TIME_HIRES); | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 24 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=7 SCAR=21.8
| |||||||||||||||||||||||||||||
| 36 | 24 | my $pkg = shift; | |||||||||||||||||||||||||||
| 37 | 24 | our $NO_TIME_HIRES; | |||||||||||||||||||||||||||
| 38 | 24 | my @sym; | |||||||||||||||||||||||||||
| 39 | 24 | for my $sym (@_) { | |||||||||||||||||||||||||||
| 40 | 32 | ▶ | if ($sym eq 'NO_TIME_HIRES') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 0 | $NO_TIME_HIRES = 1; | |||||||||||||||||||||||||||
| 42 | } else { | ||||||||||||||||||||||||||||
| 43 | 32 | push @sym, $sym; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 24 | ▶ | if (!$NO_TIME_HIRES) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 24 | eval { require Time::HiRes; }; | |||||||||||||||||||||||||||
| 49 | 24 | ▶ | if ($@ =~ /^Can\'t locate Time/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 50 | # OK, just continue | ||||||||||||||||||||||||||||
| 51 | } elsif ($@) { | ||||||||||||||||||||||||||||
| 52 | 0 | ▶ | die if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | } else { | ||||||||||||||||||||||||||||
| 54 | 24 | cache_time_api(); # hook in high precision time | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 24 | $pkg->export_to_level(1, undef, @sym); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | # broadcast_adjust for Time::Warp? XXX | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 125 | ▶ | sub _load_watcher { | ||||||||||||||||||||||||||
|
Subroutine
_load_watcher: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||
| 64 | 125 | my $sub = shift; | |||||||||||||||||||||||||||
| 65 | 125 | eval { require "Event/$sub.pm" }; | |||||||||||||||||||||||||||
| 66 | 125 | ▶ | die if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 125 | ▶ | croak "Event/$sub.pm did not define Event::$sub\::new" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | unless defined &$sub; | ||||||||||||||||||||||||||||
| 69 | 125 | 1; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 73 | 0 | my $sub = ($Event::AUTOLOAD =~ /(\w+)$/)[0]; | |||||||||||||||||||||||||||
| 74 | 0 | ▶ | _load_watcher($sub) or croak $@ . ', Undefined subroutine &' . $sub; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | carp "Autoloading with Event->$sub(...) is deprecated; | |||||||||||||||||||||||||||
| 76 | \tplease 'use Event::type qw($sub);' explicitly"; | ||||||||||||||||||||||||||||
| 77 | 0 | goto &$sub; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 1 | ▶ | sub default_exception_handler { | ||||||||||||||||||||||||||
|
Subroutine
default_exception_handler: called CC=4 SCAR=14.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 81 | 1 | my ($run,$err) = @_; | |||||||||||||||||||||||||||
| 82 | 1 | my $desc = '?'; | |||||||||||||||||||||||||||
| 83 | 1 | my $w; | |||||||||||||||||||||||||||
| 84 | 1 | ▶ | if ($run and ($w = $run->w)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$run and $w = $run->w
MC/DC0%0/2
$run and $w = $run->w
$run
$w = $run->w
Truth table33%1/3
A and B
A= $runB= $w = $run->w
| |||||||||||||||||||||||||||||
| 85 | 1 | $desc = "`".$w->desc."'"; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | 1 | my $m = "Event: trapped error in $desc: $err"; | |||||||||||||||||||||||||||
| 88 | 1 | ▶ | $m .= "\n" if $m !~ m/\n$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 1 | warn $m; | |||||||||||||||||||||||||||
| 90 | #Carp::cluck "Event: fatal error trapped in '$desc'"; | ||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 1 | ▶ | sub verbose_exception_handler { #AUTOLOAD XXX | ||||||||||||||||||||||||||
|
Subroutine
verbose_exception_handler: called CC=7 SCAR=19.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 94 | 1 | my ($e,$err) = @_; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 1 | my $m = "Event: trapped error: $err"; | |||||||||||||||||||||||||||
| 97 | 1 | ▶ | $m .= "\n" if $m !~ m/\n$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 1 | ▶ | return warn $m if !$e; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 1 | my $w = $e->w; | |||||||||||||||||||||||||||
| 101 | 1 | $m .= " in $w --\n"; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 1 | for my $k ($w->attributes) { | |||||||||||||||||||||||||||
| 104 | 11 | $m .= sprintf "%18s: ", $k; | |||||||||||||||||||||||||||
| 105 | 11 | eval { | |||||||||||||||||||||||||||
| 106 | 11 | my $v = $w->$k(); | |||||||||||||||||||||||||||
| 107 | 11 | ▶ | if (!defined $v) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 108 | 1 | $m .= '<undef>'; | |||||||||||||||||||||||||||
| 109 | } elsif ($v =~ /^-?\d+(\.\d+)?$/) { | ||||||||||||||||||||||||||||
| 110 | 5 | $m .= $v; | |||||||||||||||||||||||||||
| 111 | } else { | ||||||||||||||||||||||||||||
| 112 | 5 | $m .= "'$v'"; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | }; | ||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if ($@) { $m .= "[$@]"; $@=''; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 11 | $m .= "\n"; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | 1 | warn $m; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 3 | ▶ | sub sweep { | ||||||||||||||||||||||||||
|
Subroutine
sweep: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 122 | 3 | ▶ | my $prio = @_ ? shift : QUEUES(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 3 | queue_pending(); | |||||||||||||||||||||||||||
| 124 | 3 | my $errsv = ''; | |||||||||||||||||||||||||||
| 125 | 3 | while (1) { | |||||||||||||||||||||||||||
| 126 | 5 | eval { $@ = $errsv; _empty_queue($prio) }; | |||||||||||||||||||||||||||
| 127 | 5 | $errsv = $@; | |||||||||||||||||||||||||||
| 128 | 5 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | # if ($Event::DebugLevel >= 2) { | ||||||||||||||||||||||||||||
| 130 | # my $e = all_running(); | ||||||||||||||||||||||||||||
| 131 | # warn "Event: '$e->{desc}' died with: $@"; | ||||||||||||||||||||||||||||
| 132 | # } | ||||||||||||||||||||||||||||
| 133 | next | ||||||||||||||||||||||||||||
| 134 | 2 | } | |||||||||||||||||||||||||||
| 135 | 3 | last; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 25 | ▶ | use vars qw($Result $TopResult); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 25 | my $loop_timer; | |||||||||||||||||||||||||||
| 142 | 117 | ▶ | sub loop { | ||||||||||||||||||||||||||
|
Subroutine
loop: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||
| 143 | 25 | ▶ | use integer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 144 | 117 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 2 | my $how_long = shift; | |||||||||||||||||||||||||||
| 146 | 2 | ▶ | if (!$loop_timer) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | $loop_timer = Event->timer(desc => "Event::loop timeout", | ||||||||||||||||||||||||||||
| 148 | after => $how_long, | ||||||||||||||||||||||||||||
| 149 | 1 | ▶ | cb => sub { unloop($how_long) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 150 | 1 | parked=>1); | |||||||||||||||||||||||||||
| 151 | 1 | $loop_timer->prio(PRIO_HIGH()); | |||||||||||||||||||||||||||
| 152 | } else { | ||||||||||||||||||||||||||||
| 153 | 1 | $loop_timer->at(Event::time() + $how_long), | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | 2 | $loop_timer->start; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | 117 | $TopResult = undef; # allow re-entry of loop after unloop_all | |||||||||||||||||||||||||||
| 158 | 117 | local $Result = undef; | |||||||||||||||||||||||||||
| 159 | 117 | _incr_looplevel(); | |||||||||||||||||||||||||||
| 160 | 117 | my $errsv = ''; | |||||||||||||||||||||||||||
| 161 | 117 | while (1) { | |||||||||||||||||||||||||||
| 162 | # like G_EVAL | G_KEEPERR | ||||||||||||||||||||||||||||
| 163 | 121 | eval { $@ = $errsv; _loop() }; | |||||||||||||||||||||||||||
| 164 | 121 | $errsv = $@; | |||||||||||||||||||||||||||
| 165 | 121 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | 4 | ▶ | warn "Event::loop caught: $@" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 167 | if $Event::DebugLevel >= 4; | ||||||||||||||||||||||||||||
| 168 | next | ||||||||||||||||||||||||||||
| 169 | 4 | } | |||||||||||||||||||||||||||
| 170 | 117 | last; | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | 117 | _decr_looplevel(); | |||||||||||||||||||||||||||
| 173 | 117 | ▶ | $loop_timer->stop if $loop_timer; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | 117 | my $r = $Result; | |||||||||||||||||||||||||||
| 175 | 117 | ▶ | $r = $TopResult if !defined $r; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | 117 | ▶ | warn "Event: unloop(".(defined $r?$r:'<undef>').")\n" | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 177 | if $Event::DebugLevel >= 3; | ||||||||||||||||||||||||||||
| 178 | 117 | $r | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 128 | ▶ | sub add_hooks { | ||||||||||||||||||||||||||
|
Subroutine
add_hooks: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 182 | 128 | ▶ | shift if @_ & 1; #? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | 128 | ▶ | while (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | 4 | my $k = shift; | |||||||||||||||||||||||||||
| 185 | 4 | my $v = shift; | |||||||||||||||||||||||||||
| 186 | 4 | ▶ | croak "$v must be CODE" if ref $v ne 'CODE'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | 4 | _add_hook($k, $v); | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 25 | ▶ | END { $_->cancel for all_watchers() } # buggy? XXX | ||||||||||||||||||||||||||
|
Subroutine
END: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | package Event::Event::Io; | ||||||||||||||||||||||||||||
| 194 | 25 | ▶ | use vars qw(@ISA); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 195 | 25 | @ISA = 'Event::Event'; | |||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | package Event::Event::Dataful; | ||||||||||||||||||||||||||||
| 198 | 25 | ▶ | use vars qw(@ISA); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 199 | 25 | @ISA = 'Event::Event'; | |||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | package Event; | ||||||||||||||||||||||||||||
| 202 | 25 | require Event::Watcher; | |||||||||||||||||||||||||||
| 203 | 25 | _load_watcher($_) for qw(idle io signal timer var); | |||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | # Provide hints to Inline.pm for usage: | ||||||||||||||||||||||||||||
| 206 | # use Inline with => 'Event'; | ||||||||||||||||||||||||||||
| 207 | 3 | ▶ | sub Inline { | ||||||||||||||||||||||||||
|
Subroutine
Inline: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 208 | 3 | my ($class, $language) = @_; | |||||||||||||||||||||||||||
| 209 | 3 | require Event::MakeMaker; | |||||||||||||||||||||||||||
| 210 | 3 | my $path = $Event::MakeMaker::installsitearch; | |||||||||||||||||||||||||||
| 211 | 3 | require Config; | |||||||||||||||||||||||||||
| 212 | 3 | my $so = $Config::Config{so}; | |||||||||||||||||||||||||||
| 213 | return { | ||||||||||||||||||||||||||||
| 214 | 3 | INC => "-I $path/Event", | |||||||||||||||||||||||||||
| 215 | TYPEMAPS => "$path/Event/typemap", | ||||||||||||||||||||||||||||
| 216 | MYEXTLIB => "$path/auto/Event/Event.$so", | ||||||||||||||||||||||||||||
| 217 | AUTO_INCLUDE => '#include "EventAPI.h"', | ||||||||||||||||||||||||||||
| 218 | BOOT => 'I_EVENT_API("Inline");', | ||||||||||||||||||||||||||||
| 219 | }; | ||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 25 | 1; | |||||||||||||||||||||||||||