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   12521 use strict;
  1         2  
  1         37  
2 1     1   6 use warnings;
  1         1  
  1         70  
3              
4             package Locale::Simple::Scraper::ParserShortcuts;
5             BEGIN {
6 1     1   33 $Locale::Simple::Scraper::ParserShortcuts::AUTHORITY = 'cpan:GETTY';
7             }
8             $Locale::Simple::Scraper::ParserShortcuts::VERSION = '0.017';
9             # ABSTRACT: LSS::Parser methods that are generic shortcuts to P::MGC functionality
10              
11 1     1   5 use Moo::Role;
  1         2  
  1         6  
12              
13             has debug_sub => (
14             is => 'ro',
15             default => sub {
16             sub { shift, warn "- " . sprintf shift() . "\n", @_ }
17             }
18             );
19              
20 468     468 0 3183 sub debug { shift->debug_sub->( @_ ) }
21              
22             sub collect_from {
23 96     96 0 163 my ( $self, $methods ) = @_;
24 96         108 return map { $self->$_ } @{$methods};
  185         3396  
  96         193  
25             }
26              
27             sub named_token {
28 140     140 0 232 my ( $self, $name, $type ) = @_;
29 140   100     507 $type ||= "constant_string";
30 140 100   140   921 my $token = $self->maybe( sub { $self->$type } ) or $self->fail( "Expected $name" );
  140         1806  
31 102         3722 return $token;
32             }
33              
34             sub c_expect_escaped {
35 164     164 0 268 my ( $self, $char ) = @_;
36             return sub {
37 8     8   574 $self->expect( qr/\\\Q$char\E/ );
38 3         117 return $char;
39 164         762 };
40             }
41              
42             sub warn_failure {
43 94     94 0 139 my ( $self, $f ) = @_;
44 94   33     369 my ( $linenum, $col, $text ) = $self->where( $f->{pos} || $self->pos );
45 94         25582 my $indent = substr( $text, 0, $col );
46 94         614 $_ =~ s/\t/ /g for $text, $indent;
47 94         994 $indent =~ s/./-/g; # blank out all the non-whitespace
48 94         158 $text =~ s/\%/%%/g;
49 94         395 $self->debug( "$f->{message}:\n |$text\n |$indent^" );
50 94         2720 return;
51             }
52              
53             sub c_any_of {
54 291     291 0 1055 my ( $self, @args ) = @_;
55             return sub {
56 601     601   30950 $self->any_of( @args );
57 291         1343 };
58             }
59              
60             sub c_expect {
61 164     164 0 321 my ( $self, @args ) = @_;
62             return sub {
63 113     113   1373 $self->expect( @args );
64 164         847 };
65             }
66              
67             sub c_with_ws {
68 288     288 0 1937 my ( $self, $code, @args ) = @_;
69             return sub {
70 108     108   14703 local $self->{patterns}{ws} = qr//;
71 108         515 return $self->$code( @args );
72 288         2161 };
73             }
74              
75             sub with_ws {
76 253     253 0 527 my ( $self, $code, @args ) = @_;
77 253         1039 local $self->{patterns}{ws} = qr//;
78 253         878 return $self->$code( @args );
79             }
80              
81             1;
82              
83             __END__