File Coverage

lib/AutoCode/AttributeType.pm
Criterion Covered Total %
statement 22 37 59.4
branch 6 12 50.0
condition n/a
subroutine 5 7 71.4
pod 0 1 0.0
total 33 57 57.8


line stmt bran cond sub pod time code
1             package AutoCode::AttributeType;
2 5     5   25 use strict;
  5         9  
  5         155  
3 5     5   26 use warnings;
  5         8  
  5         158  
4 5     5   25 use AutoCode::Root;
  5         8  
  5         27  
5             our @ISA=qw(AutoCode::Root);
6              
7             use AutoCode::AccessorMaker(
8 5         32 '$'=>[qw(string context category content required)]
9 5     5   25 );
  5         9  
10              
11             our $PRIMITIVE_TYPE='cvidft';
12              
13             sub _initialize {
14 0     0   0 my ($self, @args)=@_;
15 0         0 my ($string)= $self->_rearrange([qw(string)], @args);
16 0 0       0 defined $string or $self->throw("string is definitely required");
17 0         0 $self->string($string);
18 0         0 $self->_classify_self;
19             }
20              
21             sub _classify_self {
22 0     0   0 my $self=shift;
23 0         0 my $string = $self->string;
24 0         0 my ($context, $category, $content, $required)=$self->_classify($string);
25 0         0 $self->context($context);
26 0         0 $self->catogory($category);
27 0         0 $self->content($content);
28 0         0 $self->required($required);
29             }
30              
31             sub classify {
32 39     39 0 54 my ($self, $string)=@_;
33            
34 39 50       159 $self->throw("[$string] must start with [%@\$]")
35             unless $string =~ s/^([\%\@\$])//;
36 39         80 my $context=$1;
37 39         94 my $required=$string=~s/\!$//;
38              
39 39         41 my ($category, $content);
40 39         63 local $_=$string;
41 39 100       432 if(/^$/){
    50          
    50          
    50          
42 24         42 ($category, $content)=('P', 'v255'); # Default
43             }elsif(/^([$PRIMITIVE_TYPE])(([\+\^]?[\d]+)(\.\d+)?)?(U?)$/){
44 0         0 ($category, $content)=('P', $string);
45             }elsif(/^\{([^}]+)\}$/){
46 0         0 ($category, $content)=('E', $1);
47             }elsif(/^([_A-Z]\w+)$/){
48 15         39 ($category, $content)=('M', $1);
49             }else{
50 0         0 $self->throw("[$string] does not match any kind of pattern");
51             }
52 39         170 return ($context, $category, $content, $required);
53             }
54              
55             1;