Toolkit/Role/CaseMap.pm

filter: Statementstmt 100% 25 / 25 Branchbran 50.0% 3 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 92.6% 38 / 41 CC 4 SCAR 4.8
CC
4
Cov
90%
lower
2.0
upper
2.0
equal
2.0
CRAP 1.6
« Mode/Set.pm ↑ Summary Mode/Single.pm »
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
BranchTrueFalseTotal
unless defined $val 0 1 1
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
BranchTrueFalseTotal
unless defined $val 0 1 1
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
BranchTrueFalseTotal
unless @_ == 3 0 2 2
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
« Mode/Set.pm ↑ Summary Mode/Single.pm »