File Coverage

blib/lib/DWH_File/Tie/Hash/Node.pm
Criterion Covered Total %
statement 41 41 100.0
branch 16 16 100.0
condition 1 3 33.3
subroutine 9 9 100.0
pod 0 5 0.0
total 67 74 90.5


line stmt bran cond sub pod time code
1             package DWH_File::Tie::Hash::Node;
2              
3 9     9   52 use strict;
  9         15  
  9         377  
4 9     9   49 use vars qw( @ISA $VERSION );
  9         19  
  9         898  
5             use overload
6 9         76 '""' => \&to_string,
7 9     9   54 fallback => 1;
  9         16  
8              
9 9     9   959 use DWH_File::Slot;
  9         33  
  9         69  
10              
11             @ISA = qw( DWH_File::Slot );
12             $VERSION = 0.01;
13              
14             sub new {
15 563     563 0 1143 my ( $this ) = @_;
16 563   33     2388 my $class = ref( $this ) || $this;
17 563         1604 my $self = { pred => undef,
18             succ => undef,
19             };
20 563         1592 bless $self, $class;
21 563         1090 return $self;
22             }
23              
24             sub from_stored {
25 513     513 0 1843 my ( $this, $kernel, $data, $subscript ) = @_;
26 513         1034 my $self = $this->new;
27 513         1158 my ( $pred_len, $succ_len ) = unpack "ll", $data;
28 513 100       1175 my $pl = $pred_len > 0 ? $pred_len : 0;
29 513 100       889 my $sl = $succ_len > 0 ? $succ_len : 0;
30 513         2417 my ( $ignore, $pred_string, $succ_string, $value_string ) =
31             unpack "a8 a$pl a$sl a*", $data;
32 513 100       2023 $pred_len > 0 and $self->{ pred } = DWH_File::Value::Factory->
33             from_stored( $kernel, $pred_string );
34 513 100       1978 $succ_len > 0 and $self->{ succ } = DWH_File::Value::Factory->
35             from_stored( $kernel, $succ_string );
36 513         1599 $self->{ value } = DWH_File::Value::Factory->from_stored( $kernel,
37             $value_string );
38 513         1152 $self->{ subscript } = $subscript;
39 513         2813 return $self;
40             }
41              
42             sub to_string {
43 1031     1031 0 1233 my ( $pred, $succ ) = @{ $_[ 0 ] }{ qw( pred succ) };
  1031         3085  
44 1031         1285 my ( $pl, $sl );
45 1031 100       2988 $pl = defined $pred ? length( "$pred" ) : -1;
46 1031 100       3605 $sl = defined $succ ? length( "$succ" ) : -1;
47 1031 100       2432 unless ( defined $pred ) { $pred = '' }
  280         407  
48 1031 100       1804 unless ( defined $succ ) { $succ = '' }
  181         304  
49 1031         3397 my $res = pack( "ll", $pl, $sl ) . "$pred$succ$_[ 0 ]->{ value }";
50 1031         10333 return $res;
51             }
52              
53 50     50 0 361 sub set_successor { $_[ 0 ]->{ succ } = $_[ 1 ] }
54              
55 37     37 0 97 sub set_predecessor { $_[ 0 ]->{ pred } = $_[ 1 ] }
56              
57             1;
58              
59             __END__