« blib/lib/Cache/Memcached/Managed/Multi.pm
↑ Summary
blib/lib/Cache/Memcached/Managed/Inactive.pm »
| 1 | |||||||||||||||||||||
| 2 | # make sure we can do sockets | ||||||||||||||||||||
| 3 | 6 | ▶ | use IO::Socket (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 6 | ▶ | use Data::Dumper (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | # some local lexicals | ||||||||||||||||||||
| 7 | 6 | my $text; | |||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | # satisy -require- | ||||||||||||||||||||
| 10 | 6 | 1; | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | #------------------------------------------------------------------------ | ||||||||||||||||||||
| 13 | # anyport | ||||||||||||||||||||
| 14 | # | ||||||||||||||||||||
| 15 | # Return a free port for listening | ||||||||||||||||||||
| 16 | # | ||||||||||||||||||||
| 17 | # IN: 1 servername or IP address (defaults to "localhost") | ||||||||||||||||||||
| 18 | # OUT: 1 random port number | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | sub anyport { | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | # attempt to obtain a port to work on | ||||||||||||||||||||
| 23 | 8 | ▶ | my $port = ''; | ||||||||||||||||||
|
Subroutine
anyport: called CC=3 SCAR=11.3
| |||||||||||||||||||||
| 24 | 8 | ▶ | if (my $socket = IO::Socket::INET->new( | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
shift() || '127.0.0.1'
MC/DC0%0/1
shift() || '127.0.0.1'
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||
| 25 | Listen => 5, | ||||||||||||||||||||
| 26 | LocalAddr => (shift || '127.0.0.1'), | ||||||||||||||||||||
| 27 | ) ) { | ||||||||||||||||||||
| 28 | 8 | $port = $socket->sockport; | |||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | # make sure the system's freed up the port | ||||||||||||||||||||
| 32 | 8 | sleep 1; | |||||||||||||||||||
| 33 | 8 | return $port; | |||||||||||||||||||
| 34 | } #anyport | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | #------------------------------------------------------------------------ | ||||||||||||||||||||
| 37 | # ft | ||||||||||||||||||||
| 38 | # | ||||||||||||||||||||
| 39 | # Helper sub for doing tests inside a forked process | ||||||||||||||||||||
| 40 | # | ||||||||||||||||||||
| 41 | # a. called without parameter in void context: initialize | ||||||||||||||||||||
| 42 | # b. called with parameter in void context: add test result + comment | ||||||||||||||||||||
| 43 | # c. called without parameter in scalar context: return result | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | sub ft { | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | # completed, return what we got | ||||||||||||||||||||
| 48 | 0 | ▶ | if ( defined wantarray ) { | ||||||||||||||||||
|
Subroutine
ft: not called CC=4 SCAR=30.0
Branch: 2 branches
| |||||||||||||||||||||
| 49 | 0 | return $text; | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | # we're getting a test, return its result | ||||||||||||||||||||
| 53 | elsif (@_) { | ||||||||||||||||||||
| 54 | 0 | ▶ | $text .= ($_[0] || '')."#$_[1]\n"; | ||||||||||||||||||
|
Condition0%0/2
$_[0] || ''
MC/DC0%0/1
$_[0] || ''
$_[0]
Truth table0%0/2
A
A= $_[0]
| |||||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | # we're initializing | ||||||||||||||||||||
| 58 | else { | ||||||||||||||||||||
| 59 | 0 | $text = ''; | |||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | } #ft | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | #------------------------------------------------------------------------ | ||||||||||||||||||||
| 64 | # pft | ||||||||||||||||||||
| 65 | # | ||||||||||||||||||||
| 66 | # Process forked test results | ||||||||||||||||||||
| 67 | # | ||||||||||||||||||||
| 68 | # IN: 1 filename to read | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | sub pft { | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | # open the file | ||||||||||||||||||||
| 73 | 0 | ▶ | open my $handle, $_[0] or die "Could not open '$_[0]': $!"; | ||||||||||||||||||
|
Subroutine
pft: not called CC=3 SCAR=24.8
Branch: 1 branch
| |||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | # process all lines | ||||||||||||||||||||
| 76 | 0 | ▶ | chomp,&ok( split "#" ) while <$handle>; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | # deny all further knowledge | ||||||||||||||||||||
| 79 | 0 | close $handle; | |||||||||||||||||||
| 80 | 0 | unlink $_[0]; | |||||||||||||||||||
| 81 | } #pft | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | #------------------------------------------------------------------------ | ||||||||||||||||||||
| 84 | # slurp | ||||||||||||||||||||
| 85 | # | ||||||||||||||||||||
| 86 | # Slurp the contents of a file | ||||||||||||||||||||
| 87 | # | ||||||||||||||||||||
| 88 | # IN: 1 filename | ||||||||||||||||||||
| 89 | # OUT: 1 contents of file | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 0 | ▶ | sub slurp { open my $handle,$_[0]; local $/; <$handle> } #slurp | ||||||||||||||||||
|
Subroutine
slurp: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | #------------------------------------------------------------------------ | ||||||||||||||||||||
| 94 | # splat | ||||||||||||||||||||
| 95 | # | ||||||||||||||||||||
| 96 | # Splat contents to a file | ||||||||||||||||||||
| 97 | # | ||||||||||||||||||||
| 98 | # IN: 1 filename | ||||||||||||||||||||
| 99 | # 2 contents of file | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 0 | ▶ | sub splat { open my $handle,">$_[0]"; print $handle $_[1] } #splat | ||||||||||||||||||
|
Subroutine
splat: not called CC=1 SCAR=6.9
| |||||||||||||||||||||