File Coverage

blib/lib/Salvation/TC/Parser.pm
Criterion Covered Total %
statement 45 59 76.2
branch 8 18 44.4
condition 2 6 33.3
subroutine 11 13 84.6
pod 0 7 0.0
total 66 103 64.0


line stmt bran cond sub pod time code
1             package Salvation::TC::Parser;
2              
3 4     4   18 use strict;
  4         5  
  4         175  
4 4     4   16 use warnings;
  4         4  
  4         108  
5              
6 4     4   12 use Module::Load ();
  4         4  
  4         39  
7 4     4   13 use Class::Inspector ();
  4         4  
  4         700  
8              
9             our $VERSION = 0.12;
10             our $BACKEND;
11              
12             {
13             my $loaded;
14              
15             sub detect {
16              
17 4     4 0 12 $_[ 0 ] -> load_backend();
18 4 50       11 return $BACKEND if defined $BACKEND;
19              
20 4 50       7 if( eval { require Salvation::TC::Parser::XS; 1 } ) {
  4         1447  
  4         14  
21              
22 4         7 $BACKEND = 'Salvation::TC::Parser::XS';
23 4         6 $loaded = 1;
24              
25             } else {
26              
27 0         0 $BACKEND = 'Salvation::TC::Parser::PP';
28             }
29              
30 4         22 $_[ 0 ] -> load_backend();
31 4         5 return $BACKEND;
32             }
33              
34             sub load_backend {
35              
36 8 100   8 0 21 return unless defined $BACKEND;
37              
38 4 50       11 unless( $loaded ) {
39              
40 0         0 $loaded = 1;
41              
42 0         0 Module::Load::load( $BACKEND );
43             }
44              
45 4         6 return;
46             }
47             }
48              
49             {
50             my $code;
51              
52             sub tokenize_type_str {
53              
54 140 100   140 0 1463 goto $code if defined $code;
55              
56 4         15 $_[ 0 ] -> detect();
57 4         9 my $name = "${BACKEND}::tokenize_type_str_impl";
58              
59 4     4   14 no strict 'refs';
  4         5  
  4         297  
60              
61 4         77 goto $code = *$name{ 'CODE' };
62             }
63             }
64              
65             {
66             my $code;
67              
68             sub tokenize_signature_str {
69              
70 0 0   0 0 0 goto $code if defined $code;
71              
72 0         0 $_[ 0 ] -> detect();
73 0         0 my $name = "${BACKEND}::tokenize_signature_str_impl";
74              
75 4     4   15 no strict 'refs';
  4         4  
  4         910  
76              
77 0         0 goto $code = *$name{ 'CODE' };
78             }
79             }
80              
81             sub parameterizable_type_class_ns {
82              
83 51     51 0 70 return 'Salvation::TC::Meta::Type::Parameterized';
84             }
85              
86             {
87             my $re = qr/^Salvation::TC::Type::(.+?)$/;
88              
89             sub look_for_type_short_name {
90              
91 0     0 0 0 my ( $self, $full_name ) = @_;
92              
93 0         0 return ( $full_name =~ $re )[ 0 ];
94             }
95             }
96              
97             sub load_parameterizable_type_class {
98              
99 51     51 0 67 my ( $self, $word ) = @_;
100              
101 51         93 my $ns = $self -> parameterizable_type_class_ns();
102 51         87 my $class = "${ns}::${word}";
103 51         49 my $parameterizable_type = '';
104              
105 51         138 local $SIG{ '__DIE__' } = 'DEFAULT';
106              
107 51 50 66     150 if(
    0          
108             Class::Inspector -> loaded( $class )
109 8         574 || eval{ Module::Load::load( $class ); 1 }
  8         100  
110             ) {
111              
112 51         1064 $parameterizable_type = $class;
113              
114             } elsif( defined( $word = $self -> look_for_type_short_name( $word ) ) ) {
115              
116 0         0 $class = "${ns}::${word}";
117              
118 0 0 0     0 if(
119             Class::Inspector -> loaded( $class )
120 0         0 || eval{ Module::Load::load( $class ); 1 }
  0         0  
121             ) {
122              
123 0         0 $parameterizable_type = $class;
124             }
125             }
126              
127 51         787 return $parameterizable_type;
128             }
129              
130             1;
131              
132             __END__