File Coverage

blib/lib/Devel/Declare/Parser/Emulate.pm
Criterion Covered Total %
statement 43 43 100.0
branch 7 8 87.5
condition n/a
subroutine 13 13 100.0
pod 4 4 100.0
total 67 68 98.5


line stmt bran cond sub pod time code
1             package Devel::Declare::Parser::Emulate;
2 1     1   1263 use strict;
  1         2  
  1         31  
3 1     1   4 use warnings;
  1         2  
  1         24  
4 1     1   4 use base 'Devel::Declare::Parser';
  1         1  
  1         69  
5 1     1   5 use Data::Dumper;
  1         2  
  1         43  
6 1     1   5 use Carp;
  1         1  
  1         57  
7              
8             __PACKAGE__->add_accessor( 'test_line' );
9 1     1   4 use Devel::Declare::Interface;
  1         2  
  1         432  
10             Devel::Declare::Interface::register_parser( 'test' );
11              
12 387     387 1 905 sub line { shift->test_line( @_ )}
13              
14             sub skipspace {
15 70     70 1 72 my $self = shift;
16 70 100       152 return unless $self->peek_remaining =~ m/^(\s+)/;
17 20         79 $self->advance(length($1));
18             }
19              
20             #XXX !BEWARE! Will not work for nested quoting, even escaped
21             # This is a very dumb implementation.
22             sub _quoted_from_dd {
23 8     8   10 my $self = shift;
24 8         24 my $start = $self->peek_num_chars(1);
25 8         31 my $end = $self->end_quote( $start );
26 8         20 my $regex = "^\\$start\([^$end]*)\\$end";
27 8         31 $self->peek_remaining =~ m/$regex/;
28 8         25 my $quoted = $1;
29              
30 8 50       22 croak( "qfdd regex: |$regex| did not get complete quote." )
31             unless $quoted;
32              
33 8         31 return ( length( $quoted ) + 2, $quoted );
34             }
35              
36             sub _peek_is_word {
37 37     37   44 my $self = shift;
38 37         87 my $start = $self->peek_num_chars(1);
39 37 100       189 return 0 unless $start =~ m/^[A-Za-z_]$/;
40 21         47 $self->peek_remaining =~ m/^(\w+)/;
41 21         135 return length($1);
42             }
43              
44             sub _linestr_offset_from_dd {
45 1     1   2 my $self = shift;
46 1         3 return length($self->line);
47             }
48              
49             sub rewrite {
50 2     2 1 3 my $self = shift;
51 2         8 $self->new_parts( $self->parts );
52 2         7 1;
53             }
54              
55             sub write_line {
56 2     2 1 4 my $self = shift;
57 2         68 $self->SUPER::write_line();
58 2 100       7 $self->_scope_end("$self") if $self->end_char eq '{';
59             }
60              
61             1;
62              
63             =head1 NAME
64              
65             Devel::Declare::Parser::Emulate - Parser that emulates Devel-Declare
66              
67             =head1 TESTING ONLY
68              
69             For testing purposes only.
70              
71             =head1 AUTHORS
72              
73             Chad Granum L
74              
75             =head1 COPYRIGHT
76              
77             Copyright (C) 2010 Chad Granum
78              
79             Devel-Declare-Parser is free software; Standard perl licence.
80              
81             Devel-Declare-Parser is distributed in the hope that it will be useful, but
82             WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
83             FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.