blib/lib/Acme/Lvalue.pm

filter: Statementstmt 80.6% 50 / 62 Branchbran 41.6% 5 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 59.2% 16 / 27 Podpod n/a totaltotal 70.3% 71 / 101 CC 9 SCAR 12.1
CC
9
Cov
74%
__ANON__
12.0
import
7.6
__ANON__
2.0
CRAP 3.4
↑ Summary
1 package Acme::Lvalue;
2  
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use v5.16.0; # earliest release with #51408 fixed
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 *VERSION = \'0.03';
9  
10 {
11 package Acme::Lvalue::Proxy;
12  
13 21 ▶ sub TIESCALAR {
Subroutine TIESCALAR: called CC=1 SCAR=0.0
14 21 my ($class, $ref, $func, $cnuf) = @_;
15 21 bless [$ref, $func, $cnuf], $class
16 }
17  
18 8 ▶ sub FETCH {
Subroutine FETCH: called CC=1 SCAR=0.0
19 8 my ($self) = @_;
20 8 $self->[1]->(${$self->[0]})
21 }
22  
23 17 ▶ sub STORE {
Subroutine STORE: called CC=1 SCAR=0.0
24 17 my ($self, $val) = @_;
25 17 my $ref = $self->[0];
26 17 $$ref = $self->[2]->($val, $$ref);
27 }
28  
29 0 ▶ sub UNTIE {}
Subroutine UNTIE: not called CC=1 SCAR=0.0
30 0 ▶ sub DESTROY {}
Subroutine DESTROY: not called CC=1 SCAR=0.0
31 }
32  
33 4 ▶use Math::Trig;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 4 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 42 ▶sub _export {
Subroutine _export: called CC=1 SCAR=0.0
37 42 my ($where, $what, $how, $woh) = @_;
38 21 ▶ my $fun = sub ($) :lvalue {
Subroutine __ANON__: called CC=1 SCAR=0.0
39 21 tie my $proxy, 'Acme::Lvalue::Proxy', \$_[0], $how, $woh;
40 21 $proxy
41 42 };
42 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
43 42 *{$where . '::' . $what} = $fun;
44 }
45  
46 our %builtins = map +($_->[0] => [eval "sub {scalar $_->[0] \$_[0]}", $_->[1]]),
47 0 ▶ [chr => sub { ord $_[0] }],
Subroutine __ANON__: not called CC=1 SCAR=6.9
48 0 ▶ [cos => sub { acos $_[0] }],
Subroutine __ANON__: not called CC=1 SCAR=6.9
49 [defined =>
50 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
51 0 ▶ $_[0]
Branch: 2 branches
BranchTrueFalseTotal
$_[0] ? : 0 0 0
defined $_[1] ? : 0 0 0
52 ? defined $_[1]
53 ? $_[1]
54 : 1
55 : undef
56 }
57 ],
58 0 ▶ [exp => sub { log $_[0] }],
Subroutine __ANON__: not called CC=1 SCAR=6.9
59 1 ▶ [hex => sub { sprintf '%x', $_[0] }],
Subroutine __ANON__: called CC=1 SCAR=0.0
60 [length =>
61 3 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
62 3 my ($n, $x) = @_;
63 3 my $l = length $x;
64 3 ▶ $n <= $l
Branch: 1 branch
BranchTrueFalseTotal
$n <= $l ? : 2 1 3
65 ? substr $x, 0, $n
66 : $x . "\0" x ($n - $l)
67 }
68 ],
69 0 ▶ [log => sub { exp $_[0] }],
Subroutine __ANON__: not called CC=1 SCAR=6.9
70 0 ▶ [oct => sub { sprintf '%o', $_[0] }],
Subroutine __ANON__: not called CC=1 SCAR=6.9
71 0 ▶ [ord => sub { chr $_[0] }],
Subroutine __ANON__: not called CC=1 SCAR=6.9
72 0 ▶ [quotemeta => sub { $_[0] =~ s/\\(.)/$1/sgr }],
Subroutine __ANON__: not called CC=1 SCAR=6.9
73 2 ▶ [reverse => sub { scalar reverse $_[0] }],
Subroutine __ANON__: called CC=1 SCAR=0.0
74 0 ▶ [sin => sub { asin $_[0] }],
Subroutine __ANON__: not called CC=1 SCAR=6.9
75 5 ▶ [sqrt => sub { my $x = shift; $x * $x }],
Subroutine __ANON__: called CC=1 SCAR=0.0
76 ;
77  
78 4 ▶sub import {
Subroutine import: called CC=6 SCAR=20.3
79 4 my $class = shift;
80 4 my $caller = caller;
81  
82 4 for my $item (@_) {
83 6 ▶ if (ref $item) {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $item) { } 3 3 6
elsif ($item eq ':builtins') { } 3 0 3
elsif ($Acme::Lvalue::builtins{$item}) { } 0 0 0
84 3 _export $caller, @$item;
85 } elsif ($item eq ':builtins') {
86 3 for my $f (keys %builtins) {
87 39 _export $caller, $f, @{$builtins{$f}};
88 }
89 } elsif ($builtins{$item}) {
90 0 _export $caller, $item, @{$builtins{$item}};
91 } else {
92 0 croak qq{"$item" is not exported by the $class module};
93 }
94 }
95 }
96  
97 4 'ok'
98 __END__
↑ Summary