File Coverage

blib/lib/DWH_File/Tie.pm
Criterion Covered Total %
statement 38 43 88.3
branch 3 4 75.0
condition 5 9 55.5
subroutine 15 19 78.9
pod 0 12 0.0
total 61 87 70.1


line stmt bran cond sub pod time code
1             package DWH_File::Tie;
2              
3 9     9   52 use warnings;
  9         17  
  9         273  
4 9     9   44 use strict;
  9         17  
  9         336  
5 9     9   43 use vars qw( @ISA $VERSION );
  9         19  
  9         704  
6             use overload
7 9         83 '""' => \&store_string,
8 9     9   48 fallback => 1;
  9         16  
9              
10 9     9   9361 use DWH_File::Cached;
  9         609  
  9         95  
11 9     9   5615 use DWH_File::Reference;
  9         25  
  9         91  
12              
13             @ISA = qw( DWH_File::Value DWH_File::Cached DWH_File::Reference );
14             $VERSION = 0.01;
15              
16             sub perform_tie {
17 61     61 0 329 my ( $this, $kernel, $ref, $id, $tail ) = @_;
18 61   33     312 my $class = ref $this || $this;
19 61         455 my $self = {
20             content => $ref,
21             kernel => $kernel,
22             string_val => '',
23             cache_count => 0,
24             };
25 61         235 bless $self, $class;
26 61   66     6709 $self->{ id } = $id || $kernel->next_id;
27 61         314 $kernel->tieing( $self );
28 61 100       145 if ( defined $id ) { $self->wake_up_call( $tail ) }
  33         148  
29 28         111 else { $self->sign_in_first_time }
30 61         257 $kernel->did_tie( $self );
31 61         350 return $self;
32             }
33              
34             # template methods
35 0     0 0 0 sub wake_up_call {} # param: tail
36 0     0 0 0 sub sign_in_first_time {}
37 0     0 0 0 sub custom_grounding { '' };
38              
39             # overridden method from DWH_File::Value
40 305     305 0 7005 sub actual_value { $_[ 0 ]->{ content } }
41              
42             sub store_string {
43             $_[ 0 ]->{ string_val } ||= $_[ 0 ]->{ kernel }->
44 1726   66 1726 0 7596 reference_string( $_[ 0 ] );
45             }
46              
47 74     74 0 8269 sub cache_key { $_[ 0 ]->{ id } }
48              
49 61     61 0 210 sub cache_up { $_[ 0 ]->{ cache_count }++ }
50              
51             sub cache_down {
52 13     13 0 42 $_[ 0 ]->{ cache_count }--;
53 13 50       203 $_[ 0 ]->{ cache_count } or $_[ 0 ]->cache_out;
54             }
55              
56 13     13 0 39 sub cache_out {}
57              
58             sub bump_refcount {
59 27     27 0 120 $_[ 0 ]->{ kernel }->bump_refcount( $_[ 0 ]->{ id } );
60             }
61              
62             sub cut_refcount {
63 2     2 0 12 $_[ 0 ]->{ kernel }->cut_refcount( $_[ 0 ]->{ id } );
64             }
65              
66             sub DESTROY {
67 0     0     %{ $_[ 0 ] } = ();
  0            
68             }
69              
70             1;
71              
72             __END__