| 1 | # $Id: TagSet.pm 284 2006-12-01 07:51:49Z chronos $ | ||||||||||||||||||||||||||
| 2 | package BBCode::TagSet; | ||||||||||||||||||||||||||
| 3 | 6 | ▶ | use BBCode::Util qw(:tag); | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 4 | 6 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 5 | 6 | ▶ | use strict; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 6 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 7 | 6 | our $VERSION = '0.34'; | |||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||
| 9 | 315 | ▶ | sub new($@):method { | ||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||
| 10 | 315 | my $class = shift; | |||||||||||||||||||||||||
| 11 | 315 | ▶ | $class = ref($class) || $class; | ||||||||||||||||||||||||
|
Condition66%2/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table66%2/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||
| 12 | 315 | my $this = bless {}, $class; | |||||||||||||||||||||||||
| 13 | 315 | ▶ | $this->add(@_) if @_; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 14 | 315 | return $this; | |||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||
| 17 | 174 | ▶ | sub keys($):method { | ||||||||||||||||||||||||
|
Subroutine
keys: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||
| 18 | 174 | return keys %{+shift}; | |||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||
| 21 | 12 | ▶ | sub clone($):method { | ||||||||||||||||||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||
| 22 | 12 | my $this = shift; | |||||||||||||||||||||||||
| 23 | 12 | my $that = $this->new(); | |||||||||||||||||||||||||
| 24 | 12 | $that->add($this); | |||||||||||||||||||||||||
| 25 | 12 | return $that; | |||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||
| 28 | 326 | ▶ | sub _args { | ||||||||||||||||||||||||
|
Subroutine
_args: called CC=14 SCAR=35.6
| |||||||||||||||||||||||||||
| 29 | 326 | my($std,$not) = splice @_, 0, 2; | |||||||||||||||||||||||||
| 30 | 326 | ▶ | while(@_) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 31 | 439 | my $arg = shift; | |||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||
| 33 | 439 | ▶ | if(ref $arg) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 34 | 174 | ▶ | if(UNIVERSAL::isa($arg,'BBCode::TagSet')) { | ||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||
| 35 | 174 | foreach($arg->keys) { | |||||||||||||||||||||||||
| 36 | 38 | $std->(); | |||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||
| 38 | } elsif(UNIVERSAL::isa($arg,'BBCode::Tag')) { | ||||||||||||||||||||||||||
| 39 | 0 | local $_ = $arg->Tag; | |||||||||||||||||||||||||
| 40 | 0 | $std->(); | |||||||||||||||||||||||||
| 41 | } elsif(ref $arg eq 'HASH') { | ||||||||||||||||||||||||||
| 42 | 0 | unshift @_, keys %$arg; | |||||||||||||||||||||||||
| 43 | } elsif(ref $arg eq 'ARRAY') { | ||||||||||||||||||||||||||
| 44 | 0 | unshift @_, @$arg; | |||||||||||||||||||||||||
| 45 | ▶ | } elsif(ref $arg eq 'SCALAR' or ref $arg eq 'REF') { | |||||||||||||||||||||||||
|
Condition0%0/3
ref $arg eq "SCALAR" or ref $arg eq "REF"
MC/DC0%0/2
ref $arg eq "SCALAR" or ref $arg eq "REF"
ref $arg eq "SCALAR"
ref $arg eq "REF"
Truth table0%0/3
A or B
A= ref $arg eq "SCALAR"B= ref $arg eq "REF"
| |||||||||||||||||||||||||||
| 46 | 0 | unshift @_, $$arg; | |||||||||||||||||||||||||
| 47 | } else { | ||||||||||||||||||||||||||
| 48 | 0 | croak qq(Invalid reference); | |||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||
| 50 | } else { | ||||||||||||||||||||||||||
| 51 | 265 | ▶ | if($arg =~ /^(!?)(:\w+)$/) { | ||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||
| 52 | 171 | local $_ = uc($2); | |||||||||||||||||||||||||
| 53 | 171 | ▶ | (($1 eq '') ? $std : $not)->(); | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 54 | } elsif($arg =~ /^(!?)(\w+)$/) { | ||||||||||||||||||||||||||
| 55 | 94 | local $_ = tagCanonical($2); | |||||||||||||||||||||||||
| 56 | 94 | ▶ | (($1 eq '') ? $std : $not)->(); | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 57 | } else { | ||||||||||||||||||||||||||
| 58 | 0 | croak qq(Malformed tag [$arg]); | |||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||
| 64 | 245 | ▶ | sub add($@):method { | ||||||||||||||||||||||||
|
Subroutine
add: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||
| 65 | 245 | my $this = shift; | |||||||||||||||||||||||||
| 66 | _args( | ||||||||||||||||||||||||||
| 67 | 277 | ▶ | sub { $this->{$_} = 1 }, | ||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 68 | 13 | ▶ | sub { delete $this->{$_} }, | ||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 69 | 245 | @_, | |||||||||||||||||||||||||
| 70 | ); | ||||||||||||||||||||||||||
| 71 | 245 | return $this; | |||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||
| 74 | 81 | ▶ | sub remove($@):method { | ||||||||||||||||||||||||
|
Subroutine
remove: called CC=1 SCAR=0.1
Pod
undocumented
| |||||||||||||||||||||||||||
| 75 | 81 | my $this = shift; | |||||||||||||||||||||||||
| 76 | _args( | ||||||||||||||||||||||||||
| 77 | 13 | ▶ | sub { delete $this->{$_} }, | ||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub { $this->{$_} = 1 }, | ||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||
| 79 | 81 | @_, | |||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||
| 81 | 81 | return $this; | |||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||
| 84 | 2919 | ▶ | sub contains($$):method { | ||||||||||||||||||||||||
|
Subroutine
contains: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||
| 85 | 2919 | my $this = shift; | |||||||||||||||||||||||||
| 86 | 2919 | my $tag = tagCanonical(shift); | |||||||||||||||||||||||||
| 87 | 2919 | ▶ | return 1 if exists $this->{$tag}; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 88 | 2452 | return 0; | |||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub toString($):method { | ||||||||||||||||||||||||
|
Subroutine
toString: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||
| 92 | 0 | my $this = shift; | |||||||||||||||||||||||||
| 93 | 0 | return join(" ", sort keys %$this); | |||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||
| 95 | 6 | *as_string = *toString; | |||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||
| 97 | 6 | 1; | |||||||||||||||||||||||||