| 1 | package IRC::Toolkit::Parser; | ||||||||||
| 2 | 2 | $IRC::Toolkit::Parser::VERSION = '0.091001'; | |||||||||
| 3 | 2 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use strictures 2; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use parent 'Exporter::Tiny'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | our @EXPORT = qw/ | |||||||||
| 8 | irc_ref_from_line | ||||||||||
| 9 | irc_line_from_ref | ||||||||||
| 10 | /; | ||||||||||
| 11 | |||||||||||
| 12 | 2 | ▶ | use Scalar::Util 'blessed', 'reftype'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 2 | ▶ | use POE::Filter::IRCv3; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 2 | my $filter = 'POE::Filter::IRCv3'; | |||||||||
| 16 | |||||||||||
| 17 | sub irc_ref_from_line { | ||||||||||
| 18 | 1 | ▶ | my $line = shift; | ||||||||
|
Subroutine
irc_ref_from_line: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 19 | 1 | ▶ | confess "Expected a line and optional filter arguments" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | unless $line; | ||||||||||
| 21 | 1 | $filter->new(@_)->get([$line])->[0] | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | sub irc_line_from_ref { | ||||||||||
| 25 | 0 | ▶ | my $ref = shift; | ||||||||
|
Subroutine
irc_line_from_ref: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 26 | 0 | ▶ | confess "Expected a HASH and optional filter arguments" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | unless reftype $ref eq 'HASH'; | ||||||||||
| 28 | 0 | ▶ | $filter->new(@_)->put([blessed $ref ? +{%$ref} : $ref])->[0] | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | =pod | ||||||||||
| 32 | |||||||||||
| 33 | =head1 NAME | ||||||||||
| 34 | |||||||||||
| 35 | IRC::Toolkit::Parser - Functional-style IRC filter interface | ||||||||||
| 36 | |||||||||||
| 37 | =head1 SYNOPSIS | ||||||||||
| 38 | |||||||||||
| 39 | use IRC::Toolkit::Parser; | ||||||||||
| 40 | |||||||||||
| 41 | my $raw_irc_line = ':avenj PRIVMSG #channel :things'; | ||||||||||
| 42 | my $ref = irc_ref_from_line( $raw_irc_line ); | ||||||||||
| 43 | my $raw_line = irc_line_from_ref( $ref, colonify => 1 ); | ||||||||||
| 44 | |||||||||||
| 45 | =head1 DESCRIPTION | ||||||||||
| 46 | |||||||||||
| 47 | A simple functional-style frontend to L<POE::Filter::IRCv3>. | ||||||||||
| 48 | |||||||||||
| 49 | This will be slower than using the filter directly, but it's convenient for | ||||||||||
| 50 | one-offs. | ||||||||||
| 51 | |||||||||||
| 52 | See L<POE::Filter::IRCv3> for details. | ||||||||||
| 53 | |||||||||||
| 54 | Also see L<IRC::Message::Object> for a handy object-oriented interface to IRC | ||||||||||
| 55 | event transformation. | ||||||||||
| 56 | |||||||||||
| 57 | =head2 irc_ref_from_line | ||||||||||
| 58 | |||||||||||
| 59 | Takes a raw IRC line and returns a HASH as described in the documentation for | ||||||||||
| 60 | L<POE::Filter::IRCv3>. | ||||||||||
| 61 | |||||||||||
| 62 | =head2 irc_line_from_ref | ||||||||||
| 63 | |||||||||||
| 64 | Takes a HASH as described in L<POE::Filter::IRCv3> and returns a raw IRC line. | ||||||||||
| 65 | |||||||||||
| 66 | =head1 AUTHOR | ||||||||||
| 67 | |||||||||||
| 68 | Jon Portnoy <avenj@cobaltirc.org> | ||||||||||
| 69 | |||||||||||
| 70 | =cut | ||||||||||
| 71 | |||||||||||
| 72 | 2 | 1; | |||||||||