| 1 | package Process::Storable; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use 5.00503; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use Storable (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use IO::Handle (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use IO::String (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use Params::Util (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 11 | ▶ | use Process::Serializable (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 11 | ▶ | use vars qw{$VERSION @ISA}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 11 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 11 | $VERSION = '0.30'; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 11 | @ISA = 'Process::Serializable'; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | # Hack IO::String to be a real IO::Handle | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 11 | ▶ | unless ( IO::String->isa('IO::Handle') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 11 | @IO::String::ISA = qw{IO::Handle IO::Seekable}; | |||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 11 | ▶ | sub serialize { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serialize: called CC=9 SCAR=22.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 11 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | # Serialize to a named file (locking it) | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 11 | ▶ | if ( defined $_[0] and ! ref $_[0] and length $_[0] ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $_[0] and not ref $_[0] and length $_[0]
defined $_[0] and not ref $_[0]
MC/DC33%1/3
defined $_[0] and not ref $_[0] and length $_[0]
defined $_[0]
not ref $_[0]
length $_[0]
Truth table50%2/4
A and not(B) and C
A= defined $_[0]B= not ref $_[0]C= length $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | return Storable::lock_nstore($self, shift); | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | # Serialize to a string (via a handle) | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 10 | ▶ | if ( Params::Util::_SCALAR0($_[0]) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | my $string = shift; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | $$string = 'pst0' . Storable::nfreeze($self); | |||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | # Serialize to a generic handle | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 9 | ▶ | if ( defined fileno($_[0]) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 8 | local $/ = undef; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 8 | return Storable::nstore_fd($self, shift); | |||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | # Serialize to an IO::Handle object | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | if ( Params::Util::_INSTANCE($_[0], 'IO::Handle') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | my $string = Storable::nfreeze($self); | |||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | my $iohandle = shift; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | $iohandle->print( 'pst0' ) or return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | $iohandle->print( $string ) or return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | # We don't support anything else | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | undef; | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 11 | ▶ | sub deserialize { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deserialize: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 11 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 11 | my $self = $class->_deserialize(@_); | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | # Integrity check | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 11 | ▶ | Params::Util::_INSTANCE($self, $class) or return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 11 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 11 | ▶ | sub _deserialize { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_deserialize: called CC=9 SCAR=22.4
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 11 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | # Serialize from a named file (locking it) | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 11 | ▶ | if ( defined $_[0] and ! ref $_[0] and length $_[0] ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $_[0] and not ref $_[0] and length $_[0]
defined $_[0] and not ref $_[0]
MC/DC33%1/3
defined $_[0] and not ref $_[0] and length $_[0]
defined $_[0]
not ref $_[0]
length $_[0]
Truth table50%2/4
A and not(B) and C
A= defined $_[0]B= not ref $_[0]C= length $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 4 | return Storable::lock_retrieve(shift); | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | # Serialize from a string (via a handle) | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 7 | ▶ | if ( Params::Util::_SCALAR0($_[0]) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | my $string = shift; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | # Remove the magic header if it exists | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | ▶ | if ( substr($$string, 0, 4) eq 'pst0' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | substr($$string, 0, 4, ''); | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | return Storable::thaw($$string); | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | # Serialize from a generic handle | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 6 | ▶ | if ( defined fileno($_[0]) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 5 | return Storable::retrieve_fd(shift); | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | # Serialize from an IO::Handle object | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | ▶ | if ( Params::Util::_INSTANCE($_[0], 'IO::Handle') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | local $/ = undef; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | my $string = $_[0]->getline; | |||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | # Remove the magic header if it exists | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | ▶ | if ( substr($string, 0, 4) eq 'pst0' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | substr($string, 0, 4, ''); | |||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | return Storable::thaw($string); | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | # We don't support anything else | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | undef; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | __END__ | ||||||||||||||||||||||||||||||||||||||||||