File Coverage

blib/lib/App/Grok/Resource/u4x.pm
Criterion Covered Total %
statement 10 28 35.7
branch 0 10 0.0
condition n/a
subroutine 4 8 50.0
pod 3 3 100.0
total 17 49 34.6


line stmt bran cond sub pod time code
1             package App::Grok::Resource::u4x;
2             BEGIN {
3 1     1   38 $App::Grok::Resource::u4x::AUTHORITY = 'cpan:HINRIK';
4             }
5             {
6             $App::Grok::Resource::u4x::VERSION = '0.26';
7             }
8              
9 1     1   5 use strict;
  1         2  
  1         37  
10 1     1   7 use warnings FATAL => 'all';
  1         2  
  1         50  
11              
12 1     1   6 use base qw(Exporter);
  1         2  
  1         421  
13             our @EXPORT_OK = qw(u4x_index u4x_fetch u4x_locate);
14             our %EXPORT_TAGS = ( ALL => [@EXPORT_OK] );
15              
16             my %index;
17              
18             sub u4x_fetch {
19 0     0 1   my ($topic) = @_;
20 0 0         _build_index() if !%index;
21              
22 0 0         return $index{$topic} if defined $index{$topic};
23 0           return;
24             }
25              
26             sub u4x_index {
27 0 0   0 1   _build_index() if !%index;
28 0           return keys %index;
29             }
30              
31             sub u4x_locate {
32 0     0 1   my ($topic) = @_;
33 0 0         _build_index() if !%index;
34 0 0         return __FILE__ if $index{$topic};
35 0           return;
36             }
37              
38             sub _build_index {
39 0     0     my $pod = do { local $/ = undef; scalar <DATA> };
  0            
  0            
40 0           my @entries = split /[\s\n]*(?==head3)/m, $pod;
41              
42 0           for my $entry (@entries) {
43 0           my ($name) = $entry =~ /=head3\s*(.*)$/m;
44 0           $index{$name} = $entry;
45             }
46 0           return;
47             }
48              
49             1;
50              
51             =encoding utf8
52              
53             =head1 NAME
54              
55             App::Grok::Resource::u4x - u4x resource for grok
56              
57             =head1 SYNOPSIS
58              
59             use strict;
60             use warnings;
61             use App::Grok::Resource::u4x qw<:ALL>;
62              
63             # a list of all terms
64             my @index = u4x_index();
65              
66             # documentation for a single term
67             my $pod = u4x_fetch('infix:<+>');
68              
69             =head1 DESCRIPTION
70              
71             This resource looks maintains an index of syntax items that can be looked up.
72             See L<http://svn.pugscode.org/pugs/docs/u4x/README>.
73              
74             =head1 FUNCTIONS
75              
76             =head2 C<u4x_index>
77              
78             Takes no arguments. Lists all syntax items.
79              
80             =head2 C<u4x_fetch>
81              
82             Takes an syntax item as an argument. Returns the documentation for it.
83              
84             =head2 C<u4x_locate>
85              
86             Takes a syntax item as an argument. Returns the file where it was found.
87              
88             =cut
89              
90             __DATA__
91             =head3 infix:<+>
92              
93             Adds two numbers together. If either of the things being added is not
94             a C<Num>, it will be converted to one before the addition. The result
95             will be of the narrowest type possible.
96              
97             =head3 prefix:<+>
98              
99             Converts an object into a C<Num>. In the case of C<List> and C<Map>, the
100             numeric value is the number of elements and C<Pair>s, respectively. Note
101             that it's commas and not parentheses alone do not create a C<List>, otherwise
102             the following might be a surprise:
103              
104             say +(4,5,6); # 3
105             say +(4); # 4
106              
107             The same surprise does not happen for arrays, though, since they convey
108             list context:
109              
110             my @a = 4;
111             say +@a; # 1
112              
113             =head3 twigil:<+>
114              
115             This twigil is deprecated. Use the C<*> twigil instead.
116              
117             =head3 regex~quantifier:<+>
118              
119             Means 'one or more of the previous atom'. In other words, it means the
120             same as C<< <{1..*}> >>.
121              
122             =head3 regex~assertion:sym<+>
123              
124             Used before and between character classes inside C<< <> >> assertions to
125             indicate the characters included in the match. Thus
126              
127             <+digit-[02468]+[4]>
128              
129             will match all odd digits and the digit 4.
130              
131             The plus at the start of an assertion is a no-op and can be left out.
132              
133             =head3 version~postfix:<+>
134              
135             The string form of a version recognizes the C<*> wildcard in place of any
136             position. It also recognizes a trailing C<+>, so
137              
138             :ver<6.2.3+>
139              
140             is short for
141              
142             :ver(v6.2.3 .. v6.2.*)
143              
144             And saying
145              
146             :ver<6.2.0+>
147              
148             specifically rules out any prereleases.
149