| 1 | package IRC::Toolkit::Role::CaseMap; | ||||||||||
| 2 | 1 | $IRC::Toolkit::Role::CaseMap::VERSION = '0.092001'; | |||||||||
| 3 | 1 | ▶ | use strictures 2; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use IRC::Toolkit::Case; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | |||||||||||
| 9 | 1 | ▶ | use Role::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | requires 'casemap'; | |||||||||
| 11 | |||||||||||
| 12 | sub lower { | ||||||||||
| 13 | 1 | ▶ | my ($self, $val) = @_; | ||||||||
|
Subroutine
lower: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 14 | 1 | ▶ | confess "lower() called without a value" unless defined $val; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 15 | 1 | lc_irc $val, $self->casemap | |||||||||
| 16 | } | ||||||||||
| 17 | |||||||||||
| 18 | sub upper { | ||||||||||
| 19 | 1 | ▶ | my ($self, $val) = @_; | ||||||||
|
Subroutine
upper: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 20 | 1 | ▶ | confess "upper() called without a value" unless defined $val; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | 1 | uc_irc $val, $self->casemap | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | sub equal { | ||||||||||
| 25 | 2 | ▶ | confess 'equal() expects two values' unless @_ == 3; | ||||||||
|
Subroutine
equal: called CC=2 SCAR=7.0
Pod
documented
Branch: 1 branch
| |||||||||||
| 26 | 2 | my ($self, $one, $two) = @_; | |||||||||
| 27 | 2 | my $cmap = $self->casemap; | |||||||||
| 28 | 2 | !! ( uc_irc($one, $cmap) eq uc_irc($two, $cmap) ) | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | 1 | 1; | |||||||||
| 32 | |||||||||||
| 33 | =pod | ||||||||||
| 34 | |||||||||||
| 35 | =head1 NAME | ||||||||||
| 36 | |||||||||||
| 37 | IRC::Toolkit::Role::CaseMap - Role for classes that track IRC casemapping | ||||||||||
| 38 | |||||||||||
| 39 | =head1 SYNOPSIS | ||||||||||
| 40 | |||||||||||
| 41 | package MyIRC; | ||||||||||
| 42 | use Moo; | ||||||||||
| 43 | |||||||||||
| 44 | has casemap => ( | ||||||||||
| 45 | is => 'rw', | ||||||||||
| 46 | default => sub { 'rfc1459' }, | ||||||||||
| 47 | coerce => sub { lc $_[0] }, | ||||||||||
| 48 | ); | ||||||||||
| 49 | |||||||||||
| 50 | with 'IRC::Toolkit::Role::CaseMap'; | ||||||||||
| 51 | |||||||||||
| 52 | sub mymeth { | ||||||||||
| 53 | my ($self, $nickname, $one, $two) = @_; | ||||||||||
| 54 | |||||||||||
| 55 | my $lowered = $self->lower( $nickname ); | ||||||||||
| 56 | my $uppered = $self->upper( $nickname ); | ||||||||||
| 57 | |||||||||||
| 58 | if ( $self->equal( $one, $two ) ) { | ||||||||||
| 59 | ... | ||||||||||
| 60 | } | ||||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | =head1 DESCRIPTION | ||||||||||
| 64 | |||||||||||
| 65 | A L<Role::Tiny> role that provides convenient helper methods for classes that | ||||||||||
| 66 | track IRC casemapping, such as IRC client libraries. | ||||||||||
| 67 | |||||||||||
| 68 | This role C<requires> a B<casemap> attribute that returns one of 'rfc1459', | ||||||||||
| 69 | 'ascii', or 'strict-rfc1459' -- see L<IRC::Toolkit::Case> for details on IRC | ||||||||||
| 70 | casemap issues. | ||||||||||
| 71 | |||||||||||
| 72 | =head2 lower | ||||||||||
| 73 | |||||||||||
| 74 | Returns the IRC-lowercased string. | ||||||||||
| 75 | |||||||||||
| 76 | =head2 upper | ||||||||||
| 77 | |||||||||||
| 78 | Returns the IRC-uppercased string. | ||||||||||
| 79 | |||||||||||
| 80 | =head2 equal | ||||||||||
| 81 | |||||||||||
| 82 | Expects two strings; returns true if they are equal per the current B<casemap> | ||||||||||
| 83 | rules. Returns empty list if the strings do not match. | ||||||||||
| 84 | |||||||||||
| 85 | =head1 AUTHOR | ||||||||||
| 86 | |||||||||||
| 87 | Jon Portnoy <avenj@cobaltirc.org> | ||||||||||
| 88 | |||||||||||
| 89 | =cut | ||||||||||