File Coverage

examples/parse-dict.pl
Criterion Covered Total %
statement 25 27 92.5
branch n/a
condition n/a
subroutine 9 10 90.0
pod n/a
total 34 37 91.8


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3 1     1   457133 use v5.14;
  1         5  
4 1     1   12 use warnings;
  1         2  
  1         156  
5              
6             package DictParser;
7 1     1   9 use base qw( Parser::MGC );
  1         1  
  1         724  
8              
9 1     1   27 use Feature::Compat::Try;
  1         2  
  1         9  
10              
11             sub parse
12             {
13 9     9   11 my $self = shift;
14              
15             $self->any_of(
16             'token_int',
17             'token_string',
18              
19 3     3   15 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         82 );
23             }
24              
25             sub parse_dict
26             {
27 3     3   5 my $self = shift;
28              
29 3         3 my %ret;
30             $self->list_of( ",", sub {
31 5     5   15 my $key = $self->token_ident;
32              
33 5         34 $self->expect( ":" );
34 5         11 $self->commit;
35              
36 5         13 $ret{$key} = $self->parse;
37 3         40 } );
38              
39 3         12 return \%ret
40             }
41              
42 1     1   1135 use Data::Dumper;
  1         10251  
  1         313  
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;