File Coverage

blib/lib/DWH_File/Value/Factory.pm
Criterion Covered Total %
statement 53 61 86.8
branch 25 34 73.5
condition 4 9 44.4
subroutine 12 12 100.0
pod 0 2 0.0
total 94 118 79.6


line stmt bran cond sub pod time code
1             package DWH_File::Value::Factory;
2              
3 9     9   49 use warnings;
  9         18  
  9         285  
4 9     9   436 use strict;
  9         18  
  9         300  
5 9     9   45 use vars qw( @ISA $VERSION );
  9         18  
  9         497  
6              
7 9     9   52 use UNIVERSAL;
  9         14  
  9         44  
8              
9 9     9   7207 use DWH_File::Value::Plain;
  9         26  
  9         97  
10 9     9   7279 use DWH_File::Value::Undef;
  9         468  
  9         75  
11 9     9   6338 use DWH_File::Tie::Scalar;
  9         28  
  9         88  
12 9     9   6021 use DWH_File::Tie::Array;
  9         51  
  9         1362  
13 9     9   6722 use DWH_File::Tie::Hash;
  9         30  
  9         141  
14 9     9   8601 use DWH_File::Tie::Foreign;
  9         23  
  9         175  
15              
16             @ISA = qw( );
17             $VERSION = 0.01;
18              
19             sub from_input {
20 707     707 0 2804 my ( $this, $kernel, $actual, $tier ) = @_;
21 707 50       1855 unless ( defined $actual ) { return DWH_File::Value::Undef->new }
  0 100       0  
22             elsif ( ref $actual ) {
23 31         47 my $ty;
24 31 50       154 if ( UNIVERSAL::isa( $actual, 'DWH_File::Aware' ) ) {
25 0   0     0 $tier ||= $actual->dwh_tier;
26             }
27 31 100       182 if ( UNIVERSAL::isa( $actual, 'SCALAR' ) ) {
    100          
    50          
28 2 100 50     18 $ty = tied $$actual or $tier ||= 'DWH_File::Tie::Scalar';
29             }
30             elsif ( UNIVERSAL::isa( $actual, 'ARRAY' ) ) {
31 16 100 50     89 $ty = tied @$actual or $tier ||= 'DWH_File::Tie::Array';
32             }
33             elsif ( UNIVERSAL::isa( $actual, 'HASH' ) ) {
34 13 50 100     127 $ty = tied %$actual or $tier ||= 'DWH_File::Tie::Hash'
35             }
36 0         0 else { die "Unable to tie $actual" }
37 31 100       81 if ( $ty ) {
38 3 50       32 if ( $ty->isa( 'DWH_File::Tie' ) ) {
39 3 100       19 if ( $ty->{ kernel } == $kernel ) { return $ty }
  1         3  
40 2         17 else { return DWH_File::Tie::Foreign->new( $kernel, $ty ) }
41             }
42 0         0 else { die "Can't handle tied data" }
43             }
44             else {
45 28 50       105 if ( UNIVERSAL::isa( $actual, 'DWH_File::Aware' ) ) {
46 0         0 $actual->dwh_pre_sign_in;
47             }
48 28         207 $ty = $tier->tie_reference( $kernel, $actual );
49 28 50       99 if ( UNIVERSAL::isa( $actual, 'DWH_File::Aware' ) ) {
50 0         0 $actual->dwh_post_sign_in( $ty );
51             }
52 28         108 $kernel->ground_reference( $ty );
53 28         93 return $ty;
54             }
55             }
56 676         2097 else { return DWH_File::Value::Plain->from_input( $actual ) }
57             }
58              
59             sub from_stored {
60 1475     1475 0 2993 my ( $this, $kernel, $stored ) = @_;
61 1475 50       6429 unless ( defined $stored ) { return DWH_File::Value::Undef->new }
  0 50       0  
    100          
62 0         0 elsif ( $stored eq '%' ) { return DWH_File::Value::Undef->new }
63             elsif ( my $val = $kernel->activate_reference( $stored ) ) {
64 294         2461 return $val;
65             }
66 1181         3799 else { return DWH_File::Value::Plain->from_stored( $stored ) }
67             }
68              
69             1;
70              
71             __END__