| 1 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | package Math::Calculator; | ||||||||||||||||||||||||||||
| 4 | { | ||||||||||||||||||||||||||||
| 5 | 3 | $Math::Calculator::VERSION = '1.022'; | |||||||||||||||||||||||||||
| 6 | } | ||||||||||||||||||||||||||||
| 7 | # ABSTRACT: a multi-stack calculator class | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | sub new { | ||||||||||||||||||||||||||||
| 11 | 2 | ▶ | bless { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 12 | stacks => { default => [] }, | ||||||||||||||||||||||||||||
| 13 | current_stack => 'default' | ||||||||||||||||||||||||||||
| 14 | } => shift | ||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | sub current_stack { | ||||||||||||||||||||||||||||
| 19 | 68 | ▶ | my ($self, $stack) = @_; | ||||||||||||||||||||||||||
|
Subroutine
current_stack: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 68 | ▶ | return $self->{current_stack} unless $stack and $stack =~ /^\w+$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$stack and $stack =~ /^\w+$/
MC/DC100%2/2
$stack and $stack =~ /^\w+$/
$stack
$stack =~ /^\w+$/
Truth table100%3/3
A and B
A= $stackB= $stack =~ /^\w+$/
| |||||||||||||||||||||||||||||
| 22 | 2 | ▶ | $self->{stacks}{$stack} = [] unless defined $self->{stacks}{$stack}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 2 | $self->{current_stack} = $stack; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 76 | ▶ | sub stack { $_[0]->{stacks}->{$_[1] ? $_[1] : $_[0]->current_stack} } | ||||||||||||||||||||||||||
|
Subroutine
stack: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 5 | ▶ | sub top { (shift)->stack->[-1] } | ||||||||||||||||||||||||||
|
Subroutine
top: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 6 | ▶ | sub clear { @{(shift)->stack} = (); } | ||||||||||||||||||||||||||
|
Subroutine
clear: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | sub push { ## no critic | ||||||||||||||||||||||||||||
| 37 | 36 | ▶ | push @{(shift)->stack}, @_; | ||||||||||||||||||||||||||
|
Subroutine
push: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | 3 | ▶ | sub push_to { CORE::push @{(shift)->stack(shift)}, @_; } | ||||||||||||||||||||||||||
|
Subroutine
push_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | sub pop { ## no critic | ||||||||||||||||||||||||||||
| 43 | 17 | ▶ | splice @{$_[0]->stack}, - (defined $_[1] ? $_[1] : 1); | ||||||||||||||||||||||||||
|
Subroutine
pop: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 3 | ▶ | sub pop_from { splice @{$_[0]->stack($_[1])}, - (defined $_[2] ? $_[2] : 1); } | ||||||||||||||||||||||||||
|
Subroutine
pop_from: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 2 | ▶ | sub from_to { $_[0]->push_to($_[2], $_[0]->pop_from($_[1], $_[3])) } | ||||||||||||||||||||||||||
|
Subroutine
from_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 2 | ▶ | sub dupe { $_[0]->push( $_[0]->top ); } | ||||||||||||||||||||||||||
|
Subroutine
dupe: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # sub _op_two { $_[0]->push( $_[1]->( $_[0]->pop(2) ) ); $_[0]->top; } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 14 | ▶ | sub _op_two { ($_[0]->_op_n(2, $_[1]))[-1] } | ||||||||||||||||||||||||||
|
Subroutine
_op_two: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 57 | sub _op_n { | ||||||||||||||||||||||||||||
| 58 | 16 | ▶ | $_[0]->push(my @r = $_[2]->( $_[0]->pop($_[1]) )); | ||||||||||||||||||||||||||
|
Subroutine
_op_n: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 59 | 16 | ▶ | wantarray ? @r : $r[-1] | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 2 | ▶ | sub twiddle { (shift)->_op_two( sub { $_[1], $_[0] } ); } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
twiddle: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 4 | ▶ | sub add { (shift)->_op_two( sub { (shift) + (shift) } ); } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
add: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | 1 | ▶ | sub subtract { (shift)->_op_two( sub { (shift) - (shift) } ); } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
subtract: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 68 | 1 | ▶ | sub multiply { (shift)->_op_two( sub { (shift) * (shift) } ); } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
multiply: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | 2 | ▶ | sub divide { (shift)->_op_two( sub { (shift) / (shift) } ); } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
divide: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | ## no critic Subroutines::ProhibitBuiltinHomonyms | ||||||||||||||||||||||||||||
| 73 | 1 | ▶ | sub modulo { (shift)->_op_two( sub { (shift) % (shift) } ); } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
modulo: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | 1 | ▶ | sub sqrt { my ($self) = @_; $self->push(2); $self->root; } | ||||||||||||||||||||||||||
|
Subroutine
sqrt: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 75 | ## use critic | ||||||||||||||||||||||||||||
| 76 | 1 | ▶ | sub raise_to { (shift)->_op_two( sub { (shift) **(shift) } ); } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
raise_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | 2 | ▶ | sub root { (shift)->_op_two( sub { (shift)**(1/(shift)) } ); } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
root: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 2 | ▶ | sub _quorem { my ($n,$m) = @_; (int($n/$m), $n % $m) } | ||||||||||||||||||||||||||
|
Subroutine
_quorem: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 81 | 1 | ▶ | sub quorem { (shift)->_op_n(2, \&_quorem ); } | ||||||||||||||||||||||||||
|
Subroutine
quorem: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | 1 | ▶ | sub divmod { (shift)->_op_n(2, \&_quorem ); } | ||||||||||||||||||||||||||
|
Subroutine
divmod: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 3 | 1; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | __END__ | ||||||||||||||||||||||||||||