| 1 | # $Id: /mirror/perl/URI-Match/trunk/lib/URI/Match.pm 8767 2007-11-08T01:41:57.358392Z daisuke $ | ||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||
| 3 | # Copyright (c) 2007 Daisuke Maki <daisuke@endeworks.jp> | ||||||||||||||||||||||||||||||||||||
| 4 | # All rights reserved. | ||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||
| 6 | package URI::Match; | ||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use URI(); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use vars ('$VERSION'); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 11 | 2 | $VERSION = '0.00001'; | |||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||
| 13 | sub URI::match_parts | ||||||||||||||||||||||||||||||||||||
| 14 | 12 | ▶ | { | ||||||||||||||||||||||||||||||||||
|
Subroutine
match_parts: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 15 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||
| 17 | 12 | ▶ | if (@_ == 1) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 18 | 2 | return $self->_match( undef, $_[0] ); | |||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||
| 21 | 10 | my $matched = 0; | |||||||||||||||||||||||||||||||||||
| 22 | 10 | my $count = 0; | |||||||||||||||||||||||||||||||||||
| 23 | 10 | ▶ | while (@_) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 24 | 12 | my($part, $cond) = splice(@_, 0, 2); | |||||||||||||||||||||||||||||||||||
| 25 | 12 | $count++; | |||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||
| 27 | 12 | ▶ | $matched++ if $self->_match( $part, $cond ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||
| 29 | 10 | return $matched == $count; | |||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||
| 32 | sub URI::_match | ||||||||||||||||||||||||||||||||||||
| 33 | 14 | ▶ | { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_match: called CC=8 SCAR=21.2
| |||||||||||||||||||||||||||||||||||||
| 34 | 14 | my ($self, $part, $cond) = @_; | |||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||
| 36 | 14 | ▶ | my $target = | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%1/2
$self->$part or ""
MC/DC0%0/1
$self->$part or ""
$self->$part
Truth table50%1/2
A
A= $self->$part
| |||||||||||||||||||||||||||||||||||||
| 37 | ! defined $part ? $self : | ||||||||||||||||||||||||||||||||||||
| 38 | $self->can($part) ? ( $self->$part || '' ) : '' | ||||||||||||||||||||||||||||||||||||
| 39 | ; | ||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||
| 41 | 14 | my $ref = ref $cond ; | |||||||||||||||||||||||||||||||||||
| 42 | 14 | ▶ | if (! $ref || $ref eq 'Regexp') { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
not $ref or $ref eq "Regexp"
MC/DC100%2/2
not $ref or $ref eq "Regexp"
not $ref
$ref eq "Regexp"
Truth table100%3/3
not(A) or B
A= not $refB= $ref eq "Regexp"
| |||||||||||||||||||||||||||||||||||||
| 43 | 10 | return $target =~ /$cond/; | |||||||||||||||||||||||||||||||||||
| 44 | } elsif ($ref eq 'CODE') { | ||||||||||||||||||||||||||||||||||||
| 45 | 2 | return $cond->($target, $self); | |||||||||||||||||||||||||||||||||||
| 46 | 2 | } elsif ( my $code = eval { $cond->can('match') } ) { | |||||||||||||||||||||||||||||||||||
| 47 | 2 | return $code->( $cond, $target, $self ); | |||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||
| 50 | 0 | return (); | |||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||
| 53 | 2 | 1; | |||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||
| 55 | __END__ | ||||||||||||||||||||||||||||||||||||