| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Image::ButtonMaker::ClassContainer; | 
| 2 | 1 |  |  | 1 |  | 6 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 35 |  | 
| 3 | 1 |  |  | 1 |  | 6 | use Image::ButtonMaker::ButtonClass; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 366 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | #### Default values for class container | 
| 6 |  |  |  |  |  |  | my @defaults = ( | 
| 7 |  |  |  |  |  |  | classes  => undef, | 
| 8 |  |  |  |  |  |  | error    => 0, | 
| 9 |  |  |  |  |  |  | errorstr => undef, | 
| 10 |  |  |  |  |  |  | ); | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | our $error; | 
| 13 |  |  |  |  |  |  | our $errorstr; | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | sub new { | 
| 17 | 0 |  |  | 0 | 0 |  | my $invocant = shift; | 
| 18 | 0 |  | 0 |  |  |  | my $class = ref($invocant) || $invocant; | 
| 19 | 0 |  |  |  |  |  | my $object = { @defaults }; | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 0 |  |  |  |  |  | bless $object, $invocant; | 
| 22 | 0 |  |  |  |  |  | return $object; | 
| 23 |  |  |  |  |  |  | } | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | sub lookup_class { | 
| 26 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 27 | 0 |  |  |  |  |  | my $name = shift; | 
| 28 | 0 |  |  |  |  |  | return $self->{classes}{$name}; | 
| 29 |  |  |  |  |  |  | }; | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | sub add_class { | 
| 33 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 34 | 0 |  |  |  |  |  | my $class_obj = shift; | 
| 35 |  |  |  |  |  |  |  | 
| 36 | 0 |  |  |  |  |  | my $name   = $class_obj->lookup_name; | 
| 37 | 0 |  |  |  |  |  | my $parent = $class_obj->lookup_parent; | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | #### Can not add class to container if parent is not there | 
| 40 | 0 | 0 |  |  |  |  | if(length($parent)) { | 
| 41 | 0 | 0 |  |  |  |  | return $self->set_error(1000, "Parent '$parent' for class '$name' not found") | 
| 42 |  |  |  |  |  |  | unless($self->lookup_class($parent)); | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 0 |  |  |  |  |  | $self->{classes}{$name} = $class_obj; | 
| 46 | 0 |  |  |  |  |  | $class_obj->set_container($self); | 
| 47 | 0 |  |  |  |  |  | return 1; | 
| 48 |  |  |  |  |  |  | } | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | sub reset_error { | 
| 52 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 53 | 0 |  |  |  |  |  | $self->{error}    = 0; | 
| 54 | 0 |  |  |  |  |  | $self->{errorstr} = ''; | 
| 55 | 0 |  |  |  |  |  | return; | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | sub set_error { | 
| 59 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 60 | 0 |  |  |  |  |  | $self->{error}    = shift; | 
| 61 | 0 |  |  |  |  |  | $self->{errorstr} = shift; | 
| 62 | 0 |  |  |  |  |  | return shift; | 
| 63 |  |  |  |  |  |  | } | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | 1; |