« web/cgi-bin/yatt.lib/YATT/Util/DirTreeBuilder.pm
↑ Summary
web/cgi-bin/yatt.lib/YATT/Util/Taint.pm »
| 1 | # -*- mode: perl; coding: utf-8 -*- | ||||||||||||||||||||
| 2 | package YATT::Util::Symbol; | ||||||||||||||||||||
| 3 | 13 | ▶ | use base qw(Exporter); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 13 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 13 | ▶ | use warnings qw(FATAL all NONFATAL misc); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 13 | ▶ | BEGIN { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 13 | our @EXPORT_OK = qw(class globref stash | |||||||||||||||||||
| 9 | fields_hash fields_hash_of_class | ||||||||||||||||||||
| 10 | add_isa lift_isa_to | ||||||||||||||||||||
| 11 | declare_alias | ||||||||||||||||||||
| 12 | define_const | ||||||||||||||||||||
| 13 | rebless_with | ||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||
| 15 | 13 | our @EXPORT = @EXPORT_OK; | |||||||||||||||||||
| 16 | } | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 13 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 13 | ▶ | use YATT::Util qw(numeric lsearch); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 18342 | ▶ | sub class { | ||||||||||||||||||
|
Subroutine
class: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 22 | 18342 | ▶ | ref $_[0] || $_[0] | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 23 | } | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 18342 | ▶ | sub globref { | ||||||||||||||||||
|
Subroutine
globref: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 26 | 18342 | my ($thing, @name) = @_; | |||||||||||||||||||
| 27 | 13 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 28 | 18342 | \*{join("::", class($thing), @name)}; | |||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 0 | ▶ | sub stash { | ||||||||||||||||||
|
Subroutine
stash: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 32 | 0 | *{globref($_[0], '')}{HASH} | |||||||||||||||||||
| 33 | 0 | } | |||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 15 | ▶ | sub declare_alias ($$) { | ||||||||||||||||||
|
Subroutine
declare_alias: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||||||||||||
| 36 | 15 | my ($name, $sub, $pack) = @_; | |||||||||||||||||||
| 37 | 15 | ▶ | $pack ||= caller; | ||||||||||||||||||
|
Condition33%1/3
$pack ||= caller
MC/DC0%0/2
$pack ||= caller
$pack
caller
Truth table33%1/3
A ||= B
A= $packB= caller
| |||||||||||||||||||||
| 38 | 15 | *{globref($pack, $name)} = $sub; | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 199 | ▶ | sub define_const { | ||||||||||||||||||
|
Subroutine
define_const: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||
| 42 | 199 | my ($name_or_glob, $value) = @_; | |||||||||||||||||||
| 43 | 199 | ▶ | my $glob = ref $name_or_glob ? $name_or_glob : globref($name_or_glob); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | 0 | ▶ | *$glob = sub () { $value }; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 17084 | ▶ | sub fields_hash_of_class { | ||||||||||||||||||
|
Subroutine
fields_hash_of_class: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 48 | 17084 | *{globref($_[0], 'FIELDS')}{HASH}; | |||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 13 | *fields_hash = do { | |||||||||||||||||||
| 52 | 13 | ▶ | if ($] >= 5.009) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 53 | 13 | \&fields_hash_of_class; | |||||||||||||||||||
| 54 | } else { | ||||||||||||||||||||
| 55 | 0 | ▶ | sub { $_[0]->[0] } | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 56 | 0 | } | |||||||||||||||||||
| 57 | }; | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 0 | ▶ | sub rebless_array_with { | ||||||||||||||||||
|
Subroutine
rebless_array_with: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 60 | 0 | my ($self, $newclass) = @_; | |||||||||||||||||||
| 61 | 0 | $self->[0] = fields_hash_of_class($newclass); | |||||||||||||||||||
| 62 | 0 | bless $self, $newclass; | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 13 | *rebless_with = do { | |||||||||||||||||||
| 66 | 13 | ▶ | if ($] >= 5.009) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 67 | 13 | require YATT::Util::SymbolHash; | |||||||||||||||||||
| 68 | 13 | \&YATT::Util::SymbolHash::rebless_hash_with; | |||||||||||||||||||
| 69 | } else { | ||||||||||||||||||||
| 70 | 0 | \&rebless_array_with; | |||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | }; | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 171 | ▶ | sub add_isa { | ||||||||||||||||||
|
Subroutine
add_isa: called CC=5 SCAR=16.7
Pod
undocumented
| |||||||||||||||||||||
| 75 | 171 | my ($pack, $targetClass, @baseClass) = @_; | |||||||||||||||||||
| 76 | 171 | my $isa = globref($targetClass, 'ISA'); | |||||||||||||||||||
| 77 | 171 | my @uniqBase; | |||||||||||||||||||
| 78 | 171 | ▶ | if (my $array = *{$isa}{ARRAY}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 79 | 171 | foreach my $baseClass (@baseClass) { | |||||||||||||||||||
| 80 | 172 | ▶ | next if $targetClass eq $baseClass; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 81 | 169 | ▶ | next if lsearch {$_ eq $baseClass} $array; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||
| 82 | 169 | push @uniqBase, $baseClass; | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | } else { | ||||||||||||||||||||
| 85 | 0 | *{$isa} = []; | |||||||||||||||||||
| 86 | 0 | @uniqBase = @baseClass; | |||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | 171 | push @{*{$isa}{ARRAY}}, @uniqBase; | |||||||||||||||||||
| 89 | } | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 13 | ▶ | sub lift_isa_to { | ||||||||||||||||||
|
Subroutine
lift_isa_to: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||
| 92 | 13 | my ($new_parent, $child) = @_; | |||||||||||||||||||
| 93 | 13 | my $orig = *{globref($child, 'ISA')}; | |||||||||||||||||||
| 94 | 13 | my $isa = *{$orig}{ARRAY}; | |||||||||||||||||||
| 95 | 0 | ▶ | *{$orig} = $isa = [] unless $isa; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 96 | 13 | my @orig = @$isa; | |||||||||||||||||||
| 97 | # croak "Multiple inheritance is not supported: $child isa @orig" | ||||||||||||||||||||
| 98 | # if @orig > 1; | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | # !!: *{$orig} = [$new_parent]; is not ok. | ||||||||||||||||||||
| 101 | 13 | @$isa = $new_parent; | |||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 13 | ▶ | return unless @orig; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 104 | 4 | add_isa(undef, $new_parent, @orig); | |||||||||||||||||||
| 105 | } | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | 13 | 1; | |||||||||||||||||||