| 1 | package IRC::Toolkit::Masks; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 3 | $IRC::Toolkit::Masks::VERSION = '0.092001'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strictures 2; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use parent 'Exporter::Tiny'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | our @EXPORT = qw/ | |||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | matches_mask | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | normalize_mask | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | parse_user | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | /; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use IRC::Toolkit::Case; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | sub matches_mask { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | ## Imported from IRC::Utils: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | ▶ | my ($mask, $nuh, $casemap) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
matches_mask: called CC=3 SCAR=11.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 3 | ▶ | confess "Expected a mask, a string to match, and optional casemap" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
length $mask and defined $nuh
MC/DC0%0/2
length $mask and defined $nuh
length $mask
defined $nuh
Truth table33%1/3
A and B
A= length $maskB= defined $nuh
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | unless length $mask and defined $nuh; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | my $quoted = quotemeta uc_irc $mask, $casemap; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 3 | $quoted =~ s/\\\*/[\x01-\xFF]{0,}/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 3 | $quoted =~ s/\\\?/[\x01-\xFF]{1,1}/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | !! ( uc_irc($nuh, $casemap) =~ /^$quoted$/ ) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | sub normalize_mask { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 7 | ▶ | my ($orig) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_mask: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 7 | ▶ | confess "normalize_mask expected a mask" unless defined $orig; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | ## Inlined with some tweaks from IRC::Utils | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ## **+ --> * | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 7 | $orig =~ s/\*{2,}/*/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 7 | my ($piece, @mask); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 7 | ▶ | if ( index($orig, '!') == -1 && index($orig, '@') > -1) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
index($orig, "!") == -1 and index($orig, "\@") != -1
MC/DC100%2/2
index($orig, "!") == -1 and index($orig, "\@") != -1
index($orig, "!") == -1
index($orig, "\@") != -1
Truth table100%3/3
A and B
A= index($orig, "!") == -1B= index($orig, "\@") != -1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # no nick, add '*' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 4 | $piece = $orig; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 4 | @mask = '*'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 3 | ($mask[0], $piece) = split /!/, $orig, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | ## user/host | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 7 | ▶ | if (defined $piece) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 6 | $piece =~ s/!//g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 6 | @mask[1, 2] = split /@/, $piece, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 7 | ▶ | $mask[2] =~ s/@//g if defined $mask[2]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 7 | ▶ | $mask[0] | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%6/6
defined $mask[1] and length $mask[1]
defined $mask[2] and length $mask[2]
MC/DC100%2/2
defined $mask[1] and length $mask[1]
defined $mask[1]
length $mask[1]
MC/DC100%2/2
defined $mask[2] and length $mask[2]
defined $mask[2]
length $mask[2]
Truth table100%3/3
A and B
A= defined $mask[1]B= length $mask[1]
Truth table100%3/3
A and B
A= defined $mask[2]B= length $mask[2]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # defined+length is annoying but elsewise we get fatal warnings on 5.10 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | . '!' . (defined $mask[1] && length $mask[1] ? $mask[1] : '*' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | . '@' . (defined $mask[2] && length $mask[2] ? $mask[2] : '*' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | sub parse_user { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 2 | ▶ | my ($full) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_user: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | ▶ | confess "parse_user() called with no arguments" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | unless defined $full; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | my ($nick, $user, $host) = split /[!@]/, $full; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 2 | ▶ | wantarray ? ($nick, $user, $host) : $nick | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | IRC::Toolkit::Masks - IRC mask-related utilities | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | use IRC::Toolkit::Masks; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | my $mask = '*!avenj@*.cobaltirc.org'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | my $full = 'avenj!avenj@eris.cobaltirc.org'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | my $casemap = 'rfc1459'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | if ( matches_mask($mask, $full, $casemap) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | ... | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | my $bmask = normalize_mask( 'somenick' ); # somenick!*@* | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | my $bmask = normalize_mask( 'user@host' ); # *!user@host | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | my ($nick, $user, $host) = parse_user( $full ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | my $nick = parse_user( $full ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | IRC mask manipulation utilities derived from L<IRC::Utils>. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | =head2 matches_mask | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | Takes an IRC mask, a string to match it against, and an optional IRC casemap | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | (see L<IRC::Toolkit::Case>). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | Returns boolean true if the match applies successfully. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | =head2 normalize_mask | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | Takes an IRC mask and returns the "normalized" version of the mask. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | =head2 parse_user | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | Splits an IRC mask into components. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | Returns all available pieces (nickname, username, and host, if applicable) in | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | list context. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | Returns just the nickname in scalar context. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | Mask-matching and normalization code derived from L<IRC::Utils>, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | copyright Chris Williams, HINRIK et al. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | Jon Portnoy <avenj@cobaltirc.org> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||