| 1 | package TUI::Objects::Stream; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: defines the class TStream | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 149 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 149 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 149 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 149 | our $VERSION = '2.000003'; | |||||||||||||||||||||||||||
| 9 | 149 | $VERSION =~ tr/_//d; | |||||||||||||||||||||||||||
| 10 | 149 | our $AUTHORITY = 'cpan:BRICKPOOL'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 149 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 149 | our @EXPORT = qw( | |||||||||||||||||||||||||||
| 14 | TStream | ||||||||||||||||||||||||||||
| 15 | new_TStream | ||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 149 | ▶ | use Hash::Util::FieldHash qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | fieldhash | ||||||||||||||||||||||||||||
| 20 | id | ||||||||||||||||||||||||||||
| 21 | 149 | ); | |||||||||||||||||||||||||||
| 22 | 149 | ▶ | use Scalar::Util qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | blessed | ||||||||||||||||||||||||||||
| 24 | weaken | ||||||||||||||||||||||||||||
| 25 | 149 | ); | |||||||||||||||||||||||||||
| 26 | 149 | ▶ | use Storable qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | freeze | ||||||||||||||||||||||||||||
| 28 | thaw | ||||||||||||||||||||||||||||
| 29 | 149 | ); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 149 | ▶ | use PerlX::Assert::PP; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 149 | ▶ | use TUI::toolkit::Types qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | is_Object | ||||||||||||||||||||||||||||
| 34 | is_Str | ||||||||||||||||||||||||||||
| 35 | 149 | ); | |||||||||||||||||||||||||||
| 36 | 149 | ▶ | use TUI::Objects::Streamable; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | sub TStream() { __PACKAGE__ } | ||||||||||||||||||||||||||||
| 39 | 8 | ▶ | sub new_TStream { __PACKAGE__->new(@_) } | ||||||||||||||||||||||||||
|
Subroutine
new_TStream: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 149 | ▶ | use constant { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | 149 | ptObject => 'TUI::Objects::Stream::ptObject', | |||||||||||||||||||||||||||
| 43 | ptIndexed => 'TUI::Objects::Stream::ptIndexed', | ||||||||||||||||||||||||||||
| 44 | 149 | }; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | # | ||||||||||||||||||||||||||||
| 47 | # Maintains a process-local database of streamable objects that have | ||||||||||||||||||||||||||||
| 48 | # been packed and are still alive. | ||||||||||||||||||||||||||||
| 49 | # | ||||||||||||||||||||||||||||
| 50 | # Used to detect repeated references across nested object streams. | ||||||||||||||||||||||||||||
| 51 | # | ||||||||||||||||||||||||||||
| 52 | 149 | fieldhash my %writtenObjects; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # | ||||||||||||||||||||||||||||
| 55 | # Maps persisted object identifiers to retrieved objects. | ||||||||||||||||||||||||||||
| 56 | # | ||||||||||||||||||||||||||||
| 57 | # Values are weak references so that this registry does not control | ||||||||||||||||||||||||||||
| 58 | # the lifetime of restored objects. | ||||||||||||||||||||||||||||
| 59 | # | ||||||||||||||||||||||||||||
| 60 | 149 | my %readObjects; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 14 | ▶ | sub new { # $obj () | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | 14 | my ( $class ) = @_; | |||||||||||||||||||||||||||
| 64 | 14 | assert ( @_ == 1 ); | |||||||||||||||||||||||||||
| 65 | 14 | assert ( is_Str $class ); | |||||||||||||||||||||||||||
| 66 | 14 | return bless [], $class; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 22 | ▶ | sub put { # $self (@values) | ||||||||||||||||||||||||||
|
Subroutine
put: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 70 | 22 | my ( $self, @values ) = @_; | |||||||||||||||||||||||||||
| 71 | 22 | assert ( @_ >= 1 ); | |||||||||||||||||||||||||||
| 72 | 22 | assert ( is_Object $self ); | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 22 | for my $value ( @values ) { | |||||||||||||||||||||||||||
| 75 | 63 | ▶ | if ( blessed $value && $value->DOES( TStreamable ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($value) and $value->DOES("TUI::Objects::Streamable")
MC/DC50%1/2
builtin::blessed($value) and $value->DOES("TUI::Objects::Streamable")
builtin::blessed($value)
$value->DOES("TUI::Objects::Streamable")
Truth table66%2/3
A and B
A= builtin::blessed($value)B= $value->DOES("TUI::Objects::Streamable")
| |||||||||||||||||||||||||||||
| 76 | 11 | ▶ | my $id = $writtenObjects{$value} // 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
$writtenObjects{$value} // 0
MC/DC100%1/1
$writtenObjects{$value} // 0
$writtenObjects{$value}
Truth table100%2/2
A
A= $writtenObjects{$value}
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 11 | ▶ | if ( $id ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 3 | $value = bless \$id => ptIndexed; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | else { | ||||||||||||||||||||||||||||
| 82 | 8 | $id = id $value; | |||||||||||||||||||||||||||
| 83 | 8 | $writtenObjects{$value} = $id; | |||||||||||||||||||||||||||
| 84 | 8 | $value = bless [ | |||||||||||||||||||||||||||
| 85 | $id, | ||||||||||||||||||||||||||||
| 86 | freeze $value | ||||||||||||||||||||||||||||
| 87 | ] => ptObject; | ||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 63 | push @$self, $value; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 22 | return $self; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 63 | ▶ | sub get { # $value () | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 98 | 63 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 99 | 63 | assert ( @_ == 1 ); | |||||||||||||||||||||||||||
| 100 | 63 | assert ( is_Object $self ); | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 63 | my $value = shift @$self; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 63 | ▶ | return $value | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | unless blessed $value; | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 11 | ▶ | if ( $value->isa( ptIndexed ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 3 | my $id = $$value; | |||||||||||||||||||||||||||
| 109 | 3 | return $readObjects{$id}; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 8 | ▶ | if ( $value->isa( ptObject ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 8 | my ( $id, $data ) = @$value; | |||||||||||||||||||||||||||
| 114 | 8 | my $ref = thaw $data; | |||||||||||||||||||||||||||
| 115 | 8 | $readObjects{$id} = $ref; | |||||||||||||||||||||||||||
| 116 | 8 | weaken $readObjects{$id}; | |||||||||||||||||||||||||||
| 117 | 8 | return $ref; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | return $value; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 149 | 1; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | __END__ | ||||||||||||||||||||||||||||