File Coverage

blib/lib/Keyword/API.pm
Criterion Covered Total %
statement 13 13 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 18 18 100.0


line stmt bran cond sub pod time code
1             package Keyword::API;
2             BEGIN {
3 2     2   2712 $Keyword::API::VERSION = '0.0004';
4             }
5 2     2   64 use 5.012;
  2         7  
  2         66  
6 2     2   11 use strict;
  2         3  
  2         67  
7 2     2   10 use warnings;
  2         4  
  2         65  
8 2     2   9 use Exporter 'import';
  2         4  
  2         220  
9             require XSLoader;
10              
11             our @EXPORT = qw/
12             install_keyword
13             uninstall_keyword
14             lex_read_space
15             lex_read
16             lex_read_to_ws
17             lex_stuff
18             lex_unstuff
19             lex_unstuff_to
20             lex_unstuff_to_ws
21             /;
22              
23             XSLoader::load('Keyword::API', $Keyword::API::VERSION);
24              
25             1;
26              
27              
28             =pod
29              
30             =head1 NAME
31              
32             Keyword::API
33              
34             =head1 VERSION
35              
36             version 0.0004
37              
38             =head1 SYNOPSIS
39              
40             use Keyword::API;
41              
42             sub import {
43             my ($class, %params) = @_;
44              
45             my $name = %params && $params{-as} ? $params{-as} : "method";
46              
47             install_keyword(__PACKAGE__, $name);
48             }
49              
50             sub unimport { uninstall_keyword() }
51              
52             sub parser {
53             lex_read_space(0);
54             my $sub_name = lex_unstuff_to_ws();
55             my $sig = lex_unstuff_to('{');
56             my ($roll) = $sig =~ /\((.+)\)\s*{/;
57             lex_stuff("sub $sub_name {my (\$self, $roll) = \@_;");
58             };
59              
60             =head1 DESCRIPTION
61              
62             This module provides a pure perl interface for the keywords API added to the perl core in 5.12.
63              
64             =head1 NAME
65              
66             Keyword::API - Perl interface to the keyword API
67              
68             =head1 EXPERIMENTAL
69              
70             This module is likely to change in the near future. Patches and feedback most welcome.
71              
72             =head2 EXPORT
73              
74             install_keyword
75             uninstall_keyword
76             lex_read_space
77             lex_read
78             lex_read_to_ws
79             lex_stuff
80             lex_unstuff
81             lex_unstuff_to
82             lex_unstuff_to_ws
83              
84             =head1 FUNCTIONS
85              
86             =head2 install_keyword
87              
88             pass your package name and provide the name of your keyword e.g 'method'
89              
90             =head2 uninstall_keyword
91              
92             remove the keyword hook, no arguments required.
93              
94             =head2 lex_read_space
95              
96             lex_read_space(0);
97              
98             reads white space and comments in the text currently being lexed.
99              
100             =head2 lex_read
101              
102             my $str = lex_read($n);
103              
104             Consumes $n bytes of text from the lexer buffer.
105              
106             =head2 lex_read_to_ws
107              
108             my $toke = lex_read_token();
109              
110             Consumes any text in the lexer until white space is reached.
111              
112             =head2 lex_stuff
113              
114             lex_stuff("sub foo { ...");
115              
116             Injects a string into the lexer buffer.
117              
118             =head2 lex_unstuff
119              
120             my $discarded_text = lex_unstuff($n);
121              
122             Discard $n bytes from the lexers buffer
123              
124             =head2 lex_unstuff_to
125              
126             my $discarded_text = lex_unstuff_to("{");
127              
128             Discard everything in the buffer until the character is met.
129              
130             =head2 lex_unstuff_to_ws
131              
132             my $discarded_text = lext_unstuff_token();
133              
134             Discard everything in the buffer until white space is met
135              
136             =head1 SEE ALSO
137              
138             L Devel::Declare Filter::Simple Syntax::Feature::Method
139              
140             =head1 AUTHOR
141              
142             Robin Edwards
143              
144             =head1 COPYRIGHT AND LICENSE
145              
146             This software is copyright (c) 2011 by Robin Edwards.
147              
148             This is free software; you can redistribute it and/or modify it under
149             the same terms as the Perl 5 programming language system itself.
150              
151             =cut
152              
153              
154             __END__