| 1 | # This module is a base class for all Lingy object classes and base classes, | ||||||||||||||||||||
| 2 | # and also a class for 'Lingy::Lang::Class' objects. | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 34 | ▶ | use strict; use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | package Lingy::Lang::Class; | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 34 | ▶ | use Lingy::Common; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | # This section is base class support for all Lingy object classes. | ||||||||||||||||||||
| 10 | # They all inherit from this: | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 34 | ▶ | use Lingy::Common(); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | sub new { | ||||||||||||||||||||
| 15 | 0 | ▶ | die sprintf "No 'new' method defined for class '%s'.", ref($_[0]); | ||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 16 | } | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | sub NAME { | ||||||||||||||||||||
| 19 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
NAME: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 20 | 0 | ▶ | my $class = ref($self) or die; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 21 | 0 | $class =~ s/^Lingy::Lang::/lingy.lang./; | |||||||||||||||||||
| 22 | 0 | return $class; | |||||||||||||||||||
| 23 | } | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 34 | my %common = map {($_, 1)} @Lingy::Common::EXPORT; | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | sub _method_names { | ||||||||||||||||||||
| 28 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
_method_names: not called CC=3 SCAR=20.0
| |||||||||||||||||||||
| 29 | 0 | ▶ | my $class = ref($self) || $self; | ||||||||||||||||||
|
Condition0%0/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table0%0/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||
| 30 | 34 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 31 | grep { | ||||||||||||||||||||
| 32 | not( | ||||||||||||||||||||
| 33 | 0 | ▶ | exists($common{$_}) or | ||||||||||||||||||
|
Condition0%0/3
exists $common{$_} || /(^_|^[A-Z]+$|can|import|isa|new)/
MC/DC0%0/2
exists $common{$_} || /(^_|^[A-Z]+$|can|import|isa|new)/
exists $common{$_}
/(^_|^[A-Z]+$|can|import|isa|new)/
Truth table0%0/3
A || B
A= exists $common{$_}B= /(^_|^[A-Z]+$|can|import|isa|new)/
| |||||||||||||||||||||
| 34 | /(^_|^[A-Z]+$|can|import|isa|new)/ | ||||||||||||||||||||
| 35 | ) | ||||||||||||||||||||
| 36 | 0 | } keys %{"$class\::"}; | |||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | # This section is for special Lingy::Lang::Class objects, which are needed to | ||||||||||||||||||||
| 41 | # mimic Clojure class behavior. | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | use overload '""' => sub { | ||||||||||||||||||||
| 44 | 0 | ▶ | ref($_[0]) eq __PACKAGE__ ? ${$_[0]} : $_[0]; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||
| 45 | 34 | ▶ | }; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | sub _new { | ||||||||||||||||||||
| 48 | 0 | ▶ | my (undef, $name) = @_; | ||||||||||||||||||
|
Subroutine
_new: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 49 | 0 | bless \$name, __PACKAGE__; | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | sub _name { | ||||||||||||||||||||
| 53 | 0 | ▶ | ref($_[0]) eq __PACKAGE__ or | ||||||||||||||||||
|
Subroutine
_name: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||
| 54 | die sprintf "Can't call '_name' on '%s' object", | ||||||||||||||||||||
| 55 | ref($_[0]); | ||||||||||||||||||||
| 56 | 0 | my $name = ${$_[0]}; | |||||||||||||||||||
| 57 | 0 | $name =~ s/^Lingy::Lang::/lingy.lang./; | |||||||||||||||||||
| 58 | 0 | return $name; | |||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | # Public methods: | ||||||||||||||||||||
| 62 | sub isInstance { | ||||||||||||||||||||
| 63 | 0 | ▶ | my ($base_class, $instance) = @_; | ||||||||||||||||||
|
Subroutine
isInstance: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 64 | 0 | my $instance_class = ref($instance); | |||||||||||||||||||
| 65 | 0 | ▶ | $instance->isa($base_class) ? true : false; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 34 | 1; | |||||||||||||||||||