File Coverage

blib/lib/Language/P/Toy/Value/Typeglob.pm
Criterion Covered Total %
statement 46 48 95.8
branch 2 4 50.0
condition 3 6 50.0
subroutine 16 17 94.1
pod 1 5 20.0
total 68 80 85.0


line stmt bran cond sub pod time code
1             package Language::P::Toy::Value::Typeglob;
2              
3 100     100   554 use strict;
  100         245  
  100         3420  
4 100     100   526 use warnings;
  100         1202  
  100         4094  
5 100     100   546 use base qw(Language::P::Toy::Value::Any);
  100         253  
  100         36087  
6              
7             __PACKAGE__->mk_ro_accessors( qw(body) );
8              
9             sub new {
10 121     121 1 282 my( $class, $args ) = @_;
11 121         851 my $self = $class->SUPER::new( $args );
12              
13 121   33     9405 $self->{body} ||= Language::P::Toy::Value::Typeglob::Body->new;
14              
15 121         1847 return $self;
16             }
17              
18             sub set_slot {
19 126     126 0 588 my( $self, $slot, $value ) = @_;
20              
21 126         617 $self->body->set_slot( $slot, $value );
22             }
23              
24             sub get_slot {
25 11     11 0 21 my( $self, $slot ) = @_;
26              
27 11 50       31 Carp::confess unless $slot;
28              
29 11         35 return $self->body->$slot;
30             }
31              
32             sub get_or_create_slot {
33 3063     3063 0 4382 my( $self, $slot ) = @_;
34              
35 3063         7881 return $self->body->get_or_create( $slot );
36             }
37              
38             sub as_boolean_int {
39 0     0 0 0 my( $self ) = @_;
40              
41 0         0 return 1;
42             }
43              
44             package Language::P::Toy::Value::Typeglob::Body;
45              
46 100     100   689 use strict;
  100         218  
  100         3150  
47 100     100   541 use warnings;
  100         312  
  100         6560  
48 100     100   704 use base qw(Class::Accessor::Fast);
  100         205  
  100         9231  
49              
50             __PACKAGE__->mk_ro_accessors( qw(scalar array hash io format subroutine) );
51              
52 100     100   73059 use Language::P::Toy::Value::Scalar;
  100         345  
  100         1317  
53 100     100   65656 use Language::P::Toy::Value::Array;
  100         310  
  100         1123  
54             # use Language::P::Toy::Value::Hash;
55 100     100   65482 use Language::P::Toy::Value::Subroutine;
  100         321  
  100         1230  
56 100     100   66842 use Language::P::Toy::Value::Handle;
  100         298  
  100         907  
57             # use Language::P::Toy::Value::Format;
58              
59             my %types =
60             ( scalar => 'Language::P::Toy::Value::Scalar',
61             array => 'Language::P::Toy::Value::Array',
62             hash => 'Language::P::Toy::Value::Hash',
63             subroutine => 'Language::P::Toy::Value::Subroutine',
64             io => 'Language::P::Toy::Value::Handle',
65             format => 'Language::P::Toy::Value::Format',
66             );
67              
68             sub set_slot {
69 126     126   952 my( $self, $slot, $value ) = @_;
70              
71 126 50       1127 die unless $self->can( $slot );
72              
73 126         518 $self->{$slot} = $value;
74             }
75              
76             sub get_or_create {
77 3063     3063   23096 my( $self, $slot ) = @_;
78              
79 3063   66     12896 return $self->{$slot} ||= $types{$slot}->new;
80             }
81              
82             1;