blib/lib/Keyword/API.pm

filter: Statementstmt 100% 16 / 16 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 100% 21 / 21 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« API.xs ↑ Summary
1 package Keyword::API;
2 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 $Keyword::API::VERSION = '0.0004';
4 }
5 2 ▶use 5.012;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 require XSLoader;
10  
11 2 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 2 XSLoader::load('Keyword::API', $Keyword::API::VERSION);
24  
25 2 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<perlapi> Devel::Declare Filter::Simple Syntax::Feature::Method
139  
140 =head1 AUTHOR
141  
142 Robin Edwards <robin.ge@gmail.com>
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__
« API.xs ↑ Summary