File Coverage

blib/lib/DBIx/MyParsePP.pm
Criterion Covered Total %
statement 52 53 98.1
branch 3 4 75.0
condition n/a
subroutine 14 14 100.0
pod 0 3 0.0
total 69 74 93.2


line stmt bran cond sub pod time code
1             package DBIx::MyParsePP;
2 6     6   156630 use strict;
  6         15  
  6         235  
3              
4 6     6   5654 use DBIx::MyParsePP::Lexer;
  6         24  
  6         558  
5 6     6   151618 use DBIx::MyParsePP::Parser;
  6         23  
  6         334  
6 6     6   4674 use DBIx::MyParsePP::Query;
  6         20  
  6         313  
7              
8              
9             our $VERSION = '0.50';
10              
11 6     6   43 use constant MYPARSEPP_YAPP => 0;
  6         10  
  6         400  
12 6     6   29 use constant MYPARSEPP_CHARSET => 1;
  6         11  
  6         226  
13 6     6   29 use constant MYPARSEPP_VERSION => 2;
  6         9  
  6         259  
14 6     6   44 use constant MYPARSEPP_SQL_MODE => 3;
  6         11  
  6         224  
15 6     6   51 use constant MYPARSEPP_CLIENT_CAPABILITIES => 4;
  6         10  
  6         276  
16 6     6   29 use constant MYPARSEPP_STMT_PREPARE_MODE => 5;
  6         11  
  6         3037  
17              
18             my %args = (
19             charset => MYPARSEPP_CHARSET,
20             version => MYPARSEPP_VERSION,
21             sql_mode => MYPARSEPP_SQL_MODE,
22             client_capabilities => MYPARSEPP_CLIENT_CAPABILITIES,
23             stmt_prepare_mode => MYPARSEPP_STMT_PREPARE_MODE
24             );
25              
26             1;
27              
28             sub new {
29 9     9 0 508 my $class = shift;
30 9         36 my $parser = bless ([], $class );
31              
32 9         37 my $max_arg = (scalar(@_) / 2) - 1;
33              
34 9         34 foreach my $i (0..$max_arg) {
35 3 50       20 if (exists $args{$_[$i * 2]}) {
36 3         15 $parser->[$args{$_[$i * 2]}] = $_[$i * 2 + 1];
37             } else {
38 0         0 warn("Unkown argument '$_[$i * 2]' to DBIx::MyParsePP->new()");
39             }
40             }
41              
42 9         93 my $yapp = DBIx::MyParsePP::Parser->new();
43 9         90 $parser->[MYPARSEPP_YAPP] = $yapp;
44 9         87 return $parser;
45             }
46              
47             sub parse {
48 11     11 0 984 my ($parser, $string) = @_;
49              
50 11         169 my $lexer = DBIx::MyParsePP::Lexer->new(
51             string => $string,
52             charset => $parser->[MYPARSEPP_CHARSET],
53             version => $parser->[MYPARSEPP_VERSION],
54             sql_mode => $parser->[MYPARSEPP_SQL_MODE],
55             client_capabilities => $parser->[MYPARSEPP_CLIENT_CAPABILITIES],
56             stmt_prepare_mode => $parser->[MYPARSEPP_CLIENT_CAPABILITIES]
57             );
58            
59 11         135 my $query = DBIx::MyParsePP::Query->new(
60             lexer => $lexer
61             );
62              
63 11         31 my $yapp = $parser->[MYPARSEPP_YAPP];
64 11     729   183 my $result = $yapp->YYParse( yylex => sub { $lexer->yylex() }, yyerror => sub { $parser->error(@_, $query) } );
  732         1816  
  2         12  
65              
66 11 100       73 if (defined $result) {
67 9         66 $query->setRoot($result->[0]);
68             }
69              
70 11         60 return $query;
71             }
72              
73             sub error {
74 2     2 0 5 my ($parser, $yapp, $query) = @_;
75 2         24 $query->setActual($yapp->YYCurval);
76 2         15 $query->setExpected($yapp->YYExpect);
77             }
78              
79             1;
80              
81             __END__