File Coverage

examples/parse-dict.pl
Criterion Covered Total %
statement 26 28 92.8
branch n/a
condition n/a
subroutine 9 10 90.0
pod n/a
total 35 38 92.1


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3 1     1   365 use strict;
  1         2  
  1         25  
4 1     1   4 use warnings;
  1         1  
  1         30  
5              
6             package DictParser;
7 1     1   4 use base qw( Parser::MGC );
  1         2  
  1         458  
8              
9 1     1   5 use Feature::Compat::Try;
  1         1  
  1         4  
10              
11             sub parse
12             {
13 9     9   10 my $self = shift;
14              
15             $self->any_of(
16             'token_int',
17             'token_string',
18              
19 3     3   8 sub { $self->committed_scope_of( "{", 'parse_dict', "}" ) },
20              
21 0     0   0 sub { $self->commit; $self->fail( "Expected integer, string, or dictionary" ) },
  0         0  
22 9         43 );
23             }
24              
25             sub parse_dict
26             {
27 3     3   3 my $self = shift;
28              
29 3         3 my %ret;
30             $self->list_of( ",", sub {
31 5     5   9 my $key = $self->token_ident;
32              
33 5         12 $self->expect( ":" );
34 5         9 $self->commit;
35              
36 5         11 $ret{$key} = $self->parse;
37 3         15 } );
38              
39 3         9 return \%ret
40             }
41              
42 1     1   690 use Data::Dumper;
  1         5685  
  1         142  
43              
44             if( !caller ) {
45             my $parser = __PACKAGE__->new;
46              
47             while( defined( my $line = ) ) {
48             try {
49             my $ret = $parser->from_string( $line );
50             print Dumper( $ret );
51             }
52             catch ( $e ) {
53             print $e;
54             }
55             }
56             }
57              
58             1;