| 1 | package AutoCode::SymbolTableUtils; | ||||||||||||||||||||||||||
| 2 | 7 | ▶ | use strict; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 3 | # It is right NOT to let this package inhert anything. | ||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||
| 6 | 0 | ▶ | sub st_by_object { | ||||||||||||||||||||||||
|
Subroutine
st_by_object: not called CC=5 SCAR=30.7
Pod
undocumented
| |||||||||||||||||||||||||||
| 7 | 0 | my ($object)=@_; | |||||||||||||||||||||||||
| 8 | 7 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 9 | 0 | foreach my $symbol(keys %{"$object\::"}){ | |||||||||||||||||||||||||
| 10 | 0 | print "$symbol\n"; | |||||||||||||||||||||||||
| 11 | 0 | my $full_name="$object\::$symbol"; | |||||||||||||||||||||||||
| 12 | 0 | foreach(qw(SCALAR ARRAY HASH CODE GLOB IO)){ | |||||||||||||||||||||||||
| 13 | 0 | ▶ | if(defined (*$full_name{$_})){ | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 14 | 0 | print "\t$_\t". ${*$full_name{$_}} ."\n"; | |||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||
| 17 | 0 | print ${"$object\::$symbol"}, "\n"; | |||||||||||||||||||||||||
| 18 | 0 | print @{"$object\::$symbol"}, "\n"; | |||||||||||||||||||||||||
| 19 | 0 | ▶ | print "CODE: ". &{"$object\::$symbol"}, "\n" if defined &{"$object\::$symbol"}; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub return_deref { | ||||||||||||||||||||||||
|
Subroutine
return_deref: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||
| 24 | 0 | my ($symbol, $ref)=@_; | |||||||||||||||||||||||||
| 25 | 0 | my %ref_prefix=( | |||||||||||||||||||||||||
| 26 | SCALAR => '$', | ||||||||||||||||||||||||||
| 27 | ARRAY => '@', | ||||||||||||||||||||||||||
| 28 | HASH => '%', | ||||||||||||||||||||||||||
| 29 | CODE => '&', | ||||||||||||||||||||||||||
| 30 | GLOB => '*' | ||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||
| 32 | 0 | my $prefix=$ref_prefix{$ref}; | |||||||||||||||||||||||||
| 33 | 0 | ▶ | unless(defined $prefix){ | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 34 | ; # something is warning | ||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||
| 37 | 0 | my $eval="${prefix}$symbol"; | |||||||||||||||||||||||||
| 38 | 0 | return eval($eval); | |||||||||||||||||||||||||
| 39 | 0 | ▶ | if($ref eq 'SCALAR'){ | ||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||
| 40 | 0 | $$symbol; | |||||||||||||||||||||||||
| 41 | }elsif($ref eq 'ARRAY'){ | ||||||||||||||||||||||||||
| 42 | 0 | @$symbol; | |||||||||||||||||||||||||
| 43 | }elsif($ref eq 'HASH'){ | ||||||||||||||||||||||||||
| 44 | 0 | %$symbol; | |||||||||||||||||||||||||
| 45 | }elsif($ref eq 'CODE'){ | ||||||||||||||||||||||||||
| 46 | 0 | &$symbol; | |||||||||||||||||||||||||
| 47 | }elsif($ref eq 'GLOB'){ | ||||||||||||||||||||||||||
| 48 | 0 | *$symbol; | |||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | sub listsub { | ||||||||||||||||||||||||
|
Subroutine
listsub: not called CC=4 SCAR=25.3
Pod
undocumented
| |||||||||||||||||||||||||||
| 53 | 0 | my ($obj)=@_; | |||||||||||||||||||||||||
| 54 | 0 | ▶ | my $pkg = ref($obj) || $obj; | ||||||||||||||||||||||||
|
Condition0%0/3
ref $obj || $obj
MC/DC0%0/2
ref $obj || $obj
ref $obj
$obj
Truth table0%0/3
A || B
A= ref $objB= $obj
| |||||||||||||||||||||||||||
| 55 | 0 | __PACKAGE__->_load_module($pkg); | |||||||||||||||||||||||||
| 56 | 0 | my @subs; | |||||||||||||||||||||||||
| 57 | 7 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 58 | 0 | foreach (keys %{"$pkg\::"}){ | |||||||||||||||||||||||||
| 59 | 0 | ▶ | push @subs, $_ if defined &$_; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||
| 61 | 0 | return @subs; | |||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||
| 64 | 2 | ▶ | sub PKG_exists_in_ST { | ||||||||||||||||||||||||
|
Subroutine
PKG_exists_in_ST: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||
| 65 | 2 | my ($pkg) = @_; | |||||||||||||||||||||||||
| 66 | 7 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 67 | 2 | return (scalar keys %{"$pkg\::"}); | |||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||
| 70 | # There are more than one way to do such. | ||||||||||||||||||||||||||
| 71 | # $glob='AutoSQL::Root::new' | ||||||||||||||||||||||||||
| 72 | # no strict 'refs'; | ||||||||||||||||||||||||||
| 73 | # defined *{$glob}{CODE}; # Way 1 | ||||||||||||||||||||||||||
| 74 | # defined &{$glob}; # Way 2 | ||||||||||||||||||||||||||
| 75 | 308 | ▶ | sub CODE_exists_in_ST { | ||||||||||||||||||||||||
|
Subroutine
CODE_exists_in_ST: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||
| 76 | 308 | my ($glob)=@_; | |||||||||||||||||||||||||
| 77 | 7 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 78 | 308 | return defined &$glob; | |||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||
| 82 | # There are differences between defined *{$glob}{CODE}; and defined &$glob; | ||||||||||||||||||||||||||
| 83 | # | ||||||||||||||||||||||||||
| 84 | # If $glob is a string, e.g. a scalar, then ,,,,,, | ||||||||||||||||||||||||||
| 85 | 7 | *detect_sub_in_symbol_table = \&CODE_exists_in_ST; | |||||||||||||||||||||||||
| 86 | 7 | *code_exists=\&CODE_exists_in_ST; | |||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub CODE_exists { | ||||||||||||||||||||||||
|
Subroutine
CODE_exists: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||
| 89 | 0 | my $glob = shift; | |||||||||||||||||||||||||
| 90 | 0 | return defined &$glob; | |||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||
| 93 | 0 | ▶ | sub ARRAY_exists { | ||||||||||||||||||||||||
|
Subroutine
ARRAY_exists: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||
| 94 | 0 | my $glob=shift; | |||||||||||||||||||||||||
| 95 | 0 | return defined &$glob; | |||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||
| 98 | 7 | 1; | |||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||
| 100 | __END__ | ||||||||||||||||||||||||||