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