Toolkit/Case/MappedString.pm

filter: Statementstmt 65.9% 29 / 44 Branchbran 20.0% 2 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 64.7% 11 / 17 Podpod 100% 6 / 6 totaltotal 62.3% 48 / 77 CC 6 SCAR 11.0
CC
6
Cov
57%
_gt
6.0
_lt
6.0
_ge
6.0
CRAP 3.0
« Toolkit.pm ↑ Summary Toolkit/Numerics.pm »
1 package IRC::Toolkit::Case::MappedString;
2 1 $IRC::Toolkit::Case::MappedString::VERSION = '0.092002';
3 1 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use IRC::Toolkit::Case;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 use overload
7 1 ▶ bool => 'length',
Subroutine BEGIN: called CC=1 SCAR=0.0
8 eq => '_eq',
9 ne => '_ne',
10 gt => '_gt',
11 lt => '_lt',
12 ge => '_ge',
13 le => '_le',
14 cmp => '_cmp',
15 '""' => 'as_string',
16 1 fallback => 1;
17  
18 =pod
19  
20 =for Pod::Coverage STR CMAP
21  
22 =cut
23  
24 sub STR () { 0 }
25 sub CMAP () { 1 }
26  
27 7 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
28 7 my ($class, $cmap, $str) = @_;
29 7 ▶ unless (defined $str) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $str) 1 6 7
30 1 $str = $cmap;
31 1 $cmap = 'rfc1459';
32 }
33 7 bless [ $str, $cmap ], $class
34 }
35  
36 0 ▶sub as_string { $_[0]->[STR] }
Subroutine as_string: not called CC=1 SCAR=6.9
Pod documented
37 1 ▶sub casemap { $_[0]->[CMAP] }
Subroutine casemap: called CC=1 SCAR=0.0
Pod documented
38 1 ▶sub length { length $_[0]->[STR] }
Subroutine length: called CC=1 SCAR=0.0
Pod documented
39  
40 2 ▶sub as_upper {
Subroutine as_upper: called CC=1 SCAR=0.0
Pod documented
41 2 my ($self) = @_;
42 2 blessed($self)->new(
43 $self->[CMAP],
44 uc_irc( $self->[STR], $self->[CMAP] )
45 )
46 }
47  
48 2 ▶sub as_lower {
Subroutine as_lower: called CC=1 SCAR=0.0
Pod documented
49 2 my ($self) = @_;
50 2 blessed($self)->new(
51 $self->[CMAP],
52 lc_irc( $self->[STR], $self->[CMAP] )
53 )
54 }
55  
56 5 ▶sub _eq {
Subroutine _eq: called CC=1 SCAR=0.0
57 5 my ($self) = @_;
58 5 eq_irc( $_[1], $self->[STR], $self->[CMAP] )
59 }
60  
61 3 ▶sub _ne {
Subroutine _ne: called CC=1 SCAR=0.0
62 3 my ($self) = @_;
63 3 ! eq_irc( $_[1], $self->[STR], $self->[CMAP] )
64 }
65  
66 0 ▶sub _cmp {
Subroutine _cmp: not called CC=1 SCAR=6.9
67 0 my ($self) = @_;
68 0 uc_irc( $self->[STR], $self->[CMAP] ) cmp uc_irc( $_[1], $self->[CMAP] )
69 }
70  
71 0 ▶sub _gt {
Subroutine _gt: not called CC=2 SCAR=17.9
72 0 ▶ return _lt( @_[0,1] ) if $_[2];
Branch: 1 branch
BranchTrueFalseTotal
if $_[2] 0 0 0
73 0 my ($self) = @_;
74 0 uc_irc( $self->[STR], $self->[CMAP] ) gt uc_irc( $_[1], $self->[CMAP] )
75 }
76  
77 0 ▶sub _lt {
Subroutine _lt: not called CC=2 SCAR=17.9
78 0 ▶ return _gt( @_[0,1] ) if $_[2];
Branch: 1 branch
BranchTrueFalseTotal
if $_[2] 0 0 0
79 0 my ($self) = @_;
80 0 uc_irc( $self->[STR], $self->[CMAP] ) lt uc_irc( $_[1], $self->[CMAP] )
81 }
82  
83 0 ▶sub _ge {
Subroutine _ge: not called CC=2 SCAR=17.9
84 0 ▶ return _le( @_[0,1] ) if $_[2];
Branch: 1 branch
BranchTrueFalseTotal
if $_[2] 0 0 0
85 0 my ($self) = @_;
86 0 uc_irc( $self->[STR], $self->[CMAP] ) ge uc_irc( $_[1], $self->[CMAP] )
87 }
88  
89 0 ▶sub _le {
Subroutine _le: not called CC=2 SCAR=17.9
90 0 ▶ return _ge( @_[0,1] ) if $_[2];
Branch: 1 branch
BranchTrueFalseTotal
if $_[2] 0 0 0
91 0 my ($self) = @_;
92 0 uc_irc( $self->[STR], $self->[CMAP] ) le uc_irc( $_[1], $self->[CMAP] )
93 }
94  
95  
96 1 1;
97  
98 =pod
99  
100 =head1 NAME
101  
102 IRC::Toolkit::Case::MappedString - Strings with casemaps attached
103  
104 =head1 SYNOPSIS
105  
106 use IRC::Toolkit::Case;
107 my $str = irc_str( strict => 'Nick^[Abc]' );
108 if ($str eq 'nick^{abc}') {
109 # true
110 }
111  
112 =head1 DESCRIPTION
113  
114 These overloaded objects represent IRC strings with a specific IRC casemap
115 attached (such as nick/channel names).
116  
117 See L<IRC::Toolkit::Case> for more details on IRC casemapping peculiarities.
118  
119 =head2 new
120  
121 Creates a new string object.
122  
123 Expects a casemap and string; if given a single argument, it is taken to be
124 the string and the casemap defaults to C<RFC1459>.
125  
126 =head2 as_string
127  
128 Returns the raw string.
129  
130 =head2 as_upper
131  
132 Returns a new string object containing the uppercased (per specified rules)
133 string.
134  
135 =head2 as_lower
136  
137 Returns a new string object containing the lowercased (per specified rules)
138 string.
139  
140 =head2 casemap
141  
142 Returns the currently-configured casemap setting.
143  
144 =head2 length
145  
146 Returns the string's length.
147  
148 =head1 AUTHOR
149  
150 Jon Portnoy <avenj@cobaltirc.org>
151  
152 =cut
« Toolkit.pm ↑ Summary Toolkit/Numerics.pm »