summaryrefslogtreecommitdiffstats
path: root/lib/Parse/Keyword.pm
blob: 7b2f72c6c5cbcd171fa4967757f4b2b479bd2695 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package Parse::Keyword;
use strict;
use warnings;
use 5.014;
# ABSTRACT: write syntax extensions in perl

use Devel::CallParser;
use XSLoader;

XSLoader::load(
    __PACKAGE__,
    exists $Parse::Keyword::{VERSION} ? ${ $Parse::Keyword::{VERSION} } : (),
);

=head1 SYNOPSIS

=head1 DESCRIPTION

=cut

=func lex_peek

=func lex_read

=func lex_read_space

=func lex_stuff

=func parse_block

=func parse_stmtseq

=func parse_fullstmt

=func parse_barestmt

=func parse_fullexpr

=func parse_listexpr

=func parse_termexpr

=func parse_arithexpr

=func compiling_package

=cut

sub import {
    my $package = shift;
    my ($keywords) = @_;

    my $caller = caller;

    for my $keyword (keys %$keywords) {
        my $sub = do {
            no strict 'refs';
            \&{ $caller . '::' . $keyword };
        };
        install_keyword_handler($sub, $keywords->{$keyword});
    }

    my @helpers = qw(
        lex_peek
        lex_read
        lex_read_space
        lex_stuff
        parse_block
        parse_stmtseq
        parse_fullstmt
        parse_barestmt
        parse_fullexpr
        parse_listexpr
        parse_termexpr
        parse_arithexpr
        compiling_package
    );

    for my $helper (@helpers) {
        no strict 'refs';
        *{ $caller . '::' . $helper } = \&{ __PACKAGE__ . '::' . $helper };
    }
}

=head1 BUGS

No known bugs.

Please report any bugs to GitHub Issues at
L<https://github.com/doy/parse-keyword/issues>.

=head1 SEE ALSO

L<Devel::Declare>

L<Devel::CallParser>

=head1 SUPPORT

You can find this documentation for this module with the perldoc command.

    perldoc Parse::Keyword

You can also look for information at:

=over 4

=item * MetaCPAN

L<https://metacpan.org/release/Parse-Keyword>

=item * RT: CPAN's request tracker

L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Parse-Keyword>

=item * Github

L<https://github.com/doy/parse-keyword>

=item * CPAN Ratings

L<http://cpanratings.perl.org/d/Parse-Keyword>

=back

=begin Pod::Coverage

  install_keyword_handler

=end Pod::Coverage

=cut

1;