File Coverage

blib/lib/Locale/Simple/Scraper/ParserShortcuts.pm
Criterion Covered Total %
statement 45 45 100.0
branch 2 2 100.0
condition 3 5 60.0
subroutine 18 18 100.0
pod 0 9 0.0
total 68 79 86.0


line stmt bran cond sub pod time code
1 1     1   14138 use strict;
  1         3  
  1         41  
2 1     1   7 use warnings;
  1         2  
  1         63  
3              
4             package Locale::Simple::Scraper::ParserShortcuts;
5             BEGIN {
6 1     1   75 $Locale::Simple::Scraper::ParserShortcuts::AUTHORITY = 'cpan:GETTY';
7             }
8             $Locale::Simple::Scraper::ParserShortcuts::VERSION = '0.019';
9             # ABSTRACT: LSS::Parser methods that are generic shortcuts to P::MGC functionality
10              
11 1     1   7 use Moo::Role;
  1         1  
  1         20  
12              
13             has debug_sub => (
14             is => 'ro',
15             default => sub {
16             sub { shift, warn "- " . sprintf shift() . "\n", @_ }
17             }
18             );
19              
20 471     471 0 1432 sub debug { shift->debug_sub->( @_ ) }
21              
22             sub collect_from {
23 97     97 0 137 my ( $self, $methods ) = @_;
24 97         106 return map { $self->$_ } @{$methods};
  186         2610  
  97         183  
25             }
26              
27             sub named_token {
28 141     141 0 199 my ( $self, $name, $type ) = @_;
29 141   100     589 $type ||= "constant_string";
30 141 100   141   926 my $token = $self->maybe( sub { $self->$type } ) or $self->fail( "Expected $name" );
  141         3943  
31 103         3078 return $token;
32             }
33              
34             sub c_expect_escaped {
35 167     167 0 238 my ( $self, $char ) = @_;
36             return sub {
37 8     8   603 $self->expect( qr/\\\Q$char\E/ );
38 3         129 return $char;
39 167         739 };
40             }
41              
42             sub warn_failure {
43 94     94 0 148 my ( $self, $f ) = @_;
44 94   33     401 my ( $linenum, $col, $text ) = $self->where( $f->{pos} || $self->pos );
45 94         15952 my $indent = substr( $text, 0, $col );
46 94         517 $_ =~ s/\t/ /g for $text, $indent;
47 94         806 $indent =~ s/./-/g; # blank out all the non-whitespace
48 94         161 $text =~ s/\%/%%/g;
49 94         644 $self->debug( "$f->{message}:\n |$text\n |$indent^" );
50 94         2645 return;
51             }
52              
53             sub c_any_of {
54 297     297 0 1255 my ( $self, @args ) = @_;
55             return sub {
56 611     611   41472 $self->any_of( @args );
57 297         1597 };
58             }
59              
60             sub c_expect {
61 167     167 0 297 my ( $self, @args ) = @_;
62             return sub {
63 116     116   1465 $self->expect( @args );
64 167         808 };
65             }
66              
67             sub c_with_ws {
68 292     292 0 2256 my ( $self, $code, @args ) = @_;
69             return sub {
70 111     111   13080 local $self->{patterns}{ws} = qr//;
71 111         407 return $self->$code( @args );
72 292         2522 };
73             }
74              
75             sub with_ws {
76 255     255 0 558 my ( $self, $code, @args ) = @_;
77 255         1094 local $self->{patterns}{ws} = qr//;
78 255         805 return $self->$code( @args );
79             }
80              
81             1;
82              
83             __END__