| 1 | package Process::YAML; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # Process that is compatible with Storable after new, and after run. | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use 5.005; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use base 'Process::Serializable'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Fcntl qw/:flock/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use YAML::Syck (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use IO::Handle (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use IO::File (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use IO::String (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use Params::Util qw/_INSTANCE/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use vars qw{$VERSION}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | $VERSION = '0.04'; | |||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | ▶ | unless ( IO::String->isa('IO::Handle') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 3 | push @IO::String::ISA, 'IO::Handle'; | |||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 3 | ▶ | unless ( IO::String->isa('IO::Seekable') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | push @IO::String::ISA, 'IO::Seekable'; | |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 4 | ▶ | sub serialize { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serialize: called CC=13 SCAR=29.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | # Serialize to a string (via a handle) | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 4 | ▶ | if ( Params::Util::_SCALAR0($_[0]) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | my $handle = IO::String->new($_[0]); | |||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | return print $handle YAML::Syck::Dump($self); | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | # Serialize to a generic handle | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 3 | ▶ | if ( Params::Util::_INSTANCE($_[0], 'IO::Handle') or fileno($_[0]) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
&Params::Util::_INSTANCE($_[0], "IO::Handle") or fileno $_[0]
MC/DC100%2/2
&Params::Util::_INSTANCE($_[0], "IO::Handle") or fileno $_[0]
&Params::Util::_INSTANCE($_[0], "IO::Handle")
fileno $_[0]
Truth table100%3/3
A or B
A= &Params::Util::_INSTANCE($_[0], "IO::Handle")B= fileno $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 2 | my $handle = $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | return print $handle YAML::Syck::Dump($self); | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | # Serialize to a file name (locking it) | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | ▶ | if ( defined $_[0] and ! ref $_[0] and length $_[0] ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $_[0] and not ref $_[0] and length $_[0]
defined $_[0] and not ref $_[0]
MC/DC0%0/3
defined $_[0] and not ref $_[0] and length $_[0]
defined $_[0]
not ref $_[0]
length $_[0]
Truth table25%1/4
A and not(B) and C
A= defined $_[0]B= not ref $_[0]C= length $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | my $fh; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | my $mode = '+<'; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | if ( not -e $_[0] ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | $mode = '+>'; | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | ▶ | if ( not open($fh, $mode, $_[0]) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | ▶ | if ( not flock($fh, LOCK_EX) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | ▶ | if ( not truncate($fh, 0) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | ▶ | if ( not print $fh YAML::Syck::Dump($self) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | ▶ | if ( not close $fh ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | # We don't support anything else | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | undef; | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 4 | ▶ | sub deserialize { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deserialize: called CC=9 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 4 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | # Deserialize from a string | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 4 | ▶ | if ( Params::Util::_SCALAR0($_[0]) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | return YAML::Syck::Load(${$_[0]}); | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | # Deserialize from a generic handle | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 3 | ▶ | if ( Params::Util::_INSTANCE($_[0], 'IO::Handle') or fileno($_[0]) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
&Params::Util::_INSTANCE($_[0], "IO::Handle") or fileno $_[0]
MC/DC100%2/2
&Params::Util::_INSTANCE($_[0], "IO::Handle") or fileno $_[0]
&Params::Util::_INSTANCE($_[0], "IO::Handle")
fileno $_[0]
Truth table100%3/3
A or B
A= &Params::Util::_INSTANCE($_[0], "IO::Handle")B= fileno $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 2 | my $handle = $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | return YAML::Syck::Load(join '', <$handle>); | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | # Deserialize from a file name (locking it) | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | ▶ | if ( defined $_[0] and ! ref $_[0] and length $_[0] ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $_[0] and not ref $_[0] and length $_[0]
defined $_[0] and not ref $_[0]
MC/DC0%0/3
defined $_[0] and not ref $_[0] and length $_[0]
defined $_[0]
not ref $_[0]
length $_[0]
Truth table25%1/4
A and not(B) and C
A= defined $_[0]B= not ref $_[0]C= length $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | my $fh; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | ▶ | if ( not open($fh, '<', $_[0]) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | ▶ | if ( not flock($fh, LOCK_SH) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | return YAML::Syck::Load(join '', <$fh>); | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | # We don't support anything else | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | undef; | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | __END__ | ||||||||||||||||||||||||||||||||||||||||||