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   15 use strict;
  4         5  
  4         145  
4 4     4   13 use warnings;
  4         4  
  4         99  
5              
6 4     4   11 use Module::Load ();
  4         4  
  4         34  
7 4     4   11 use Class::Inspector ();
  4         3  
  4         635  
8              
9             our $VERSION = 0.06;
10             our $BACKEND;
11              
12             {
13             my $loaded;
14              
15             sub detect {
16              
17 4     4 0 15 $_[ 0 ] -> load_backend();
18 4 50       9 return $BACKEND if defined $BACKEND;
19              
20 4 50       7 if( eval { require Salvation::TC::Parser::XS; 1 } ) {
  4         1504  
  0         0  
21              
22 0         0 $BACKEND = 'Salvation::TC::Parser::XS';
23 0         0 $loaded = 1;
24              
25             } else {
26              
27 4         9 $BACKEND = 'Salvation::TC::Parser::PP';
28             }
29              
30 4         34 $_[ 0 ] -> load_backend();
31 4         6 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 4         6 $loaded = 1;
41              
42 4         18 Module::Load::load( $BACKEND );
43             }
44              
45 4         38 return;
46             }
47             }
48              
49             {
50             my $code;
51              
52             sub tokenize_type_str {
53              
54 137 100   137 0 442 goto $code if defined $code;
55              
56 4         20 $_[ 0 ] -> detect();
57 4         11 my $name = "${BACKEND}::tokenize_type_str_impl";
58              
59 4     4   13 no strict 'refs';
  4         4  
  4         251  
60              
61 4         25 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   11 no strict 'refs';
  4         4  
  4         739  
76              
77 0         0 goto $code = *$name{ 'CODE' };
78             }
79             }
80              
81             sub parameterizable_type_class_ns {
82              
83 51     51 0 54 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 46 my ( $self, $word ) = @_;
100              
101 51         83 my $ns = $self -> parameterizable_type_class_ns();
102 51         69 my $class = "${ns}::${word}";
103 51         42 my $parameterizable_type = '';
104              
105 51         113 local $SIG{ '__DIE__' } = 'DEFAULT';
106              
107 51 50 66     140 if(
    0          
108             Class::Inspector -> loaded( $class )
109 8         535 || eval{ Module::Load::load( $class ); 1 }
  8         88  
110             ) {
111              
112 51         873 $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         131 return $parameterizable_type;
128             }
129              
130             1;
131              
132             __END__