| 1 | package TUI::toolkit::UO::Antlers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Moose-like sugar for the UNIVERSAL::Object based class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 115 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 115 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 115 | our $VERSION = '0.08'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 115 | our $AUTHORITY = 'cpan:BRICKPOOL'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 115 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 115 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 115 | ▶ | use UNIVERSAL::Object (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 115 | ▶ | BEGIN { $] >= 5.010 ? require mro : require MRO::Compat } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 115 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=4 SCAR=15.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | *CAN_HAZ_XS = ( !exists $ENV{PERL_ONLY} && !$ENV{PERL_ONLY} && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 115 | ▶ | do { eval q[ use Class::XSAccessor ]; !$@ } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | ? sub() { !!1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | : sub() { !!0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 115 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not exists $ENV{"PERL_ONLY"} || $ENV{"PERL_ONLY"} and do {
eval " use Class::XSAccessor ";
not $@
}
exists $ENV{'PERL_ONLY'} || $ENV{'PERL_ONLY'}
MC/DC0%0/3
not exists $ENV{"PERL_ONLY"} || $ENV{"PERL_ONLY"} and do {
eval " use Class::XSAccessor ";
not $@
}
exists $ENV{'PERL_ONLY'}
$ENV{'PERL_ONLY'}
do {
eval " use Class::XSAccessor ";
not $@
}
Truth table25%1/4
not(A || B) and C
A= exists $ENV{'PERL_ONLY'}B= $ENV{'PERL_ONLY'}C= do {
eval " use Class::XSAccessor ";
not $@
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # Export keywords | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 115 | ▶ | use Importer (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 115 | our @EXPORT = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | has | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | extends | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | blessed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | confess | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # import/unimport for setting up the class and exporting the symbols | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1493 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1493 | my ( $class, @imports ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 1493 | my $caller = caller(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # Prevent double init per compilation unit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 1493 | ▶ | return if $^H{ __PACKAGE__ . "/$caller" }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1493 | $^H{ __PACKAGE__ . "/$caller" } = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # Turn on strict/warnings for caller | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1493 | strict->import; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 1493 | warnings->import; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # When exporting 'extends', we assume that a class hierarchy exists and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # inject the base class if the class in the hierarchy has no parent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 1493 | my $exports = Importer->get( $class, @imports ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 1493 | ▶ | if ( $exports->{extends} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 1493 | require TUI::toolkit::UO::Base; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 115 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1492 | unshift( @{"${caller}::ISA"}, 'TUI::toolkit::UO::Base' ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1493 | ▶ | unless ( @{"${caller}::ISA"} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1493 | Importer->import_into( $class, $caller, @imports ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } #/ sub import | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub unimport { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unimport: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my ( $class, @imports ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | my $caller = caller(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # TODO: 'unimport' only takes effect one time, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # but at least it's consistent with 'import' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | return unless $^H{ __PACKAGE__ . "/$caller" }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $^H{ __PACKAGE__ . "/$caller" } = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my $exports = Importer->get( $class, @imports ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | Importer->unimport_from( $caller, keys %$exports ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # Public API functions for class setup and field management | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 4503 | ▶ | sub has { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has: called CC=14 SCAR=31.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 4503 | my $class = caller( 0 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 4503 | ▶ | Carp::croak( "has() requires at least one attribute name" ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | unless @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # Case 1: has 'x' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 4503 | ▶ | if ( @_ == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my ( $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | Carp::croak( "Attribute name must be a plain string" ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $name and not ref $name
MC/DC0%0/2
defined $name and not ref $name
defined $name
not ref $name
Truth table0%0/3
A and not(B)
A= defined $nameB= not ref $name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | unless defined $name && !ref $name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | add_fields( $class, $name => undef ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | add_accessor( $class, $name => 'rw' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # Case 2: has x => ( key => value, ... ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 4503 | my ( $name, @rest ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 4503 | ▶ | Carp::croak( "has($name) options must be key/value pairs" ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | unless @rest % 2 == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 4503 | my %opts = @rest; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # Check for unknown options and missing values. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 4503 | my %allowed = map { $_ => 1 } qw(is default); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 4503 | for my $key ( keys %opts ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | Carp::croak("Unknown option '$key' for has($name)") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 7672 | ▶ | unless $allowed{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 4503 | my $access = delete $opts{is}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | Carp::croak( "Option 'is' must be 'ro', 'rw' or 'bare' for has($name)" ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 4503 | ▶ | if defined $access && !grep { $_ eq $access } qw( ro rw bare ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $access and not grep({$_ eq $access;} "ro", "rw", "bare")
MC/DC0%0/2
defined $access and not grep({$_ eq $access;} "ro", "rw", "bare")
defined $access
not grep({$_ eq $access;} "ro", "rw", "bare")
Truth table66%2/3
A and not(B)
A= defined $accessB= not grep({$_ eq $access;} "ro", "rw", "bare")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # Prepare default value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 4503 | my $default; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 4503 | ▶ | if ( exists $opts{default} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 3170 | $default = do { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 3170 | my $d = delete $opts{default}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 3170 | my $r = ref $d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | $r eq 'HASH' ? sub { +{%$d} } : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | $r eq 'ARRAY' ? sub { [@$d] } : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | $r eq 'CODE' ? $d : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 3170 | ▶ | sub { $d } ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 4503 | add_fields( $class, $name => $default ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 4503 | add_accessor( $class, $name => $access ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 4503 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } #/ sub has | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # The C<extends> function adds the given parent classes to the caller's C<@ISA>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # For example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # package Foo; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # use TUI::toolkit::UO::Antlers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # extends 'Bar', 'Baz'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 1081 | ▶ | sub extends { # void (@parents) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extends: called CC=11 SCAR=25.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 1081 | my ( @parents ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 1081 | my $class = caller(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 1081 | ▶ | Carp::croak( "No parent classes provided to extends" ) unless @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # like the parent pragma we check if the parents are already loaded and load | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | # them if not. This is required to ensure that the fields are inherited | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # correctly. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 1081 | foreach my $parent ( @parents ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # sanity check for parent class names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1198 | ▶ | Carp::croak( "Parent class names must be plain strings" ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $parent and not ref $parent
MC/DC0%0/2
defined $parent and not ref $parent
defined $parent
not ref $parent
Truth table33%1/3
A and not(B)
A= defined $parentB= not ref $parent
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | unless defined $parent and !ref $parent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 1198 | ( my $file = "$parent.pm" ) =~ s{::}{/}g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 1198 | ▶ | eval { require $file; 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | or Carp::croak("Failed to load parent class $parent: $@"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 1081 | my $isa = do { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 115 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 1081 | \@{"${class}::ISA"}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # Base is always injected by import() as the first entry in @ISA. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # extends() may remove this early injection if a parent already provides Base. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 1081 | ▶ | if ( grep { $_->isa( 'TUI::toolkit::UO::Base' ) } @parents ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 1081 | ▶ | shift( @$isa ) if @$isa && $isa->[0] eq 'TUI::toolkit::UO::Base'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@$isa and $isa->[0] eq "TUI::toolkit::UO::Base"
MC/DC0%0/2
@$isa and $isa->[0] eq "TUI::toolkit::UO::Base"
@$isa
$isa->[0] eq "TUI::toolkit::UO::Base"
Truth table33%1/3
A and B
A= @$isaB= $isa->[0] eq "TUI::toolkit::UO::Base"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # get reference to %HAS (create new %HAS if necessary) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 1081 | my $has = get_fields( $class ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # %a: %HAS from this $class (without parents) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 1081 | my %b = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | %b = ( %b, %{ get_fields( $_ ) } ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | for grep { has_fields( $_ ) } reverse @$isa; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | my %a = map { $_ => $has->{$_} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | grep { !exists $b{$_} } keys %$has; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # Add the new parents to @ISA. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 1081 | push @$isa, @parents; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | # %b: %HAS from all superclasses (including new parents) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 1081 | %b = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 1058 | %b = ( %b, %{ get_fields( $_ ) } ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 1081 | for grep { has_fields( $_ ) } reverse @$isa; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # We have new parent classes, so %HAS must be regenerated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 1081 | %$has = ( %b, %a ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 1081 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } #/ sub extends | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # Alias for re-export 'blessed' and 'confess' like Moo/se does. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 115 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 115 | *blessed = \&Scalar::Util::blessed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 115 | *confess = \&Carp::confess; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | # Utility functions for class setup and field management | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # A simple check to see if the given C<$class> has a C<%HAS> hash defined. A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # simple test like C<defined %{"${class}::HAS"}> will sometimes produce typo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # warnings because it would create the hash if it was not present before. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 5996 | ▶ | sub has_fields { # $bool ($class) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_fields: called CC=4 SCAR=14.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 5996 | my ( $proto ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 5996 | ▶ | my $class = ref $proto || $proto; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 5996 | ▶ | Carp::croak( "[ARGS] class must be an object or a plain string" ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $class and not ref $class
MC/DC0%0/2
defined $class and not ref $class
defined $class
not ref $class
Truth table33%1/3
A and not(B)
A= defined $classB= not ref $class
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | unless defined $class and !ref $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 115 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 115 | ▶ | no warnings 'once'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 5996 | return defined *{"${class}::HAS"}{HASH}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # Gets a reference to the C<%HAS> hash for the given C<$class>. It will | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # autogenerate a C<%HAS> hash if one doesn't already exist. If you don't want | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # this behavior, be sure to check beforehand with L</has_fields>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 6939 | ▶ | sub get_fields { # \%HAS ($class) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_fields: called CC=5 SCAR=16.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 6939 | my ( $proto ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 6939 | ▶ | my $class = ref $proto || $proto; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 6939 | ▶ | Carp::croak( "[ARGS] class must be an object or a plain string" ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $class and not ref $class
MC/DC0%0/2
defined $class and not ref $class
defined $class
not ref $class
Truth table33%1/3
A and not(B)
A= defined $classB= not ref $class
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | unless defined $class and !ref $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # avoid possible typo warnings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 115 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 6939 | ▶ | %{"${class}::HAS"} = () unless %{"${class}::HAS"}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 6939 | return \%{"${class}::HAS"}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # Adds a bunch of C<%slots> to the given C<$class>. For example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | # # Add the public slots 'this' and 'that' to the class Foo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # require TUI::toolkit::UO::Antlers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | # TUI::toolkit::UO::Antlers::add_fields( 'Foo', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # this => sub { 'foo' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | # that => sub { 'bar' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | # ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 4503 | ▶ | sub add_fields { # void ($class, %slots) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_fields: called CC=10 SCAR=24.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 4503 | my ( $proto, @slots ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 4503 | ▶ | my $class = ref $proto || $proto; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 4503 | ▶ | Carp::croak( "[ARGS] class must be an object or a plain string" ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $class and not ref $class
MC/DC0%0/2
defined $class and not ref $class
defined $class
not ref $class
Truth table33%1/3
A and not(B)
A= defined $classB= not ref $class
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | unless defined $class and !ref $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 4503 | ▶ | Carp::croak( "[ARGS] slots must be provided as key/value pairs" ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | unless @slots % 2 == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | # Quick bail out if nothing is to be added. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 4503 | ▶ | return unless @slots; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # if %HAS does not exist, it is a base class for which %HAS must be created. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 4503 | ▶ | unless ( has_fields( $class ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | # Create empty %HAS and get the reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 295 | my $has = get_fields( $class ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 295 | my $isa = do { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 115 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 295 | \@{"${class}::ISA"}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # copy all superclass entries to %HAS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | %$has = ( %$has, %{ get_fields( $class ) } ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 295 | for grep { has_fields( $_ ) } reverse @$isa; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 4503 | my %slots = @slots; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 4503 | my $has = get_fields( $class ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 4503 | foreach ( keys %slots ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 4503 | ▶ | $has->{$_} = ref $slots{$_} eq 'CODE' ? $slots{$_} : eval 'sub { }'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 4503 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } #/ sub add_fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | # If you want to create a new accessor, use L</add_accessor>. It ensures that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | # a read/write accessor sub is created (if not already present; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # C<unless __PACKAGE__->can($field)>). C<$access> is an optional parameter that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | # supports the values C<'ro'>, C<'rw'> and C<'bare'>. If not specified, the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | # C<'rw'> access is used. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 4503 | ▶ | sub add_accessor { # void ($class, $field, |$access) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_accessor: called CC=14 SCAR=30.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 4503 | my ( $class, $field, $access ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 4503 | ▶ | $class = ref $class if blessed $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 4503 | ▶ | $access = 'rw' unless defined $access; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 4503 | ▶ | Carp::croak( "[ARGS] class must be an object or a plain string" ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $class and not ref $class
MC/DC0%0/2
defined $class and not ref $class
defined $class
not ref $class
Truth table33%1/3
A and not(B)
A= defined $classB= not ref $class
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | unless defined $class and !ref $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 4503 | ▶ | Carp::croak( "[ARGS] field must be a plain string" ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $field and not ref $field
MC/DC0%0/2
defined $field and not ref $field
defined $field
not ref $field
Truth table33%1/3
A and not(B)
A= defined $fieldB= not ref $field
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | unless defined $field and !ref $field; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 4503 | ▶ | Carp::croak( "[ARGS] access must be 'ro', 'rw' or 'bare'" ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
not defined $access or $access ne "ro" and $access ne "rw" and $access ne "bare"
$access ne "ro" and $access ne "rw" and $access ne "bare"
$access ne "ro" and $access ne "rw"
MC/DC0%0/4
not defined $access or $access ne "ro" and $access ne "rw" and $access ne "bare"
not defined $access
$access ne "ro"
$access ne "rw"
$access ne "bare"
Truth table60%3/5
not(A) or B and C and D
A= not defined $accessB= $access ne "ro"C= $access ne "rw"D= $access ne "bare"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | if !defined $access | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | || ( $access ne 'ro' && $access ne 'rw' && $access ne 'bare' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # Only create accessors unless is 'bare' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 4503 | ▶ | return if $access eq 'bare'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # Only create accessors unless exists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 3610 | ▶ | return if $class->can( $field ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # create the accessor and use the XS version if available | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 3606 | if ( CAN_HAZ_XS ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 3606 | ▶ | my $mutator = $access eq 'ro' ? 'getters' : 'accessors'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 3606 | Class::XSAccessor->import( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | class => $class, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | $mutator => { $field => $field }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | my $acc = "${class}::${field}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | unless ( exists &$acc ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 115 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | *$acc = $access eq 'ro' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | ? sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | $#_ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | ? Carp::croak( "Usage: ${class}::${field}(self)" ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | : $_[0]->{$field}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | : sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | $#_ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | ? $_[0]->{$field} = $_[1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | ▶ | : $_[0]->{$field}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } #/ unless ( exists &$acc ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | } #/ else [ if ( CAN_HAZ_XS ) ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 3606 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } #/ sub add_accessor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 115 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||