blib/lib/Acme/Cat/Schroedinger.pm

filter: Statementstmt 86.4% 32 / 37 Branchbran 70.0% 7 / 10 Conditioncond 50.0% 7 / 14 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 77.7% 14 / 18 Podpod 100% 1 / 1 totaltotal 72.4% 63 / 87 CC 12 SCAR 12.1
CC
12
Cov
75%
__ANON__
7.2
__ANON__
6.0
__ANON__
6.0
CRAP 3.3
↑ Summary
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  
4 package Acme::Cat::Schroedinger;
5  
6 =head1 NAME
7  
8 Acme::Cat::Schroedinger - objects whose behaviour is determined by attempts to inspect or interact with it.
9  
10 =head1 VERSION
11  
12 1
13  
14 =cut
15  
16 3 our $VERSION = 1;
17  
18 3 ▶use overload (
Subroutine BEGIN: called CC=1 SCAR=0.1
19 0 ▶'0+' => sub {return $_[0]->('0+')->($_[0]);},
Subroutine __ANON__: not called CC=1 SCAR=6.9
20 3 ▶'""' => sub {return $_[0]->('""')->($_[0]);},
Subroutine __ANON__: called CC=1 SCAR=0.0
21 1 ▶'@{}' => sub {return $_[0]->('@{}')->($_[0]);},
Subroutine __ANON__: called CC=1 SCAR=0.0
22 2 ▶'%{}' => sub {return $_[0]->('%{}')->($_[0]);},
Subroutine __ANON__: called CC=1 SCAR=0.0
23 1 ▶'${}' => sub {return $_[0]->('${}')->($_[0]);},
Subroutine __ANON__: called CC=1 SCAR=0.0
24 0 ▶'*{}' => sub {return $_[0]->('*{}')->($_[0]);},
Subroutine __ANON__: not called CC=1 SCAR=6.9
25 3 );
26  
27  
28 8 ▶sub new{
Subroutine new: called CC=1 SCAR=0.3
Pod documented
29 8 my $class = shift;
30 8 my %options = @_;
31 8 ▶ my $self = sub {
Subroutine __ANON__: called CC=6 SCAR=19.8
32 8 my $attr = shift;
33 8 my @caller = caller;
34 8 ▶ return sub {'meow'} unless $caller[0] eq __PACKAGE__;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
unless $caller[0] eq __PACKAGE__ 1 7 8
35 7 my %attrs = (
36 'temperament' => 'cooperative', # cooperative | perverse | random
37 'kittens' => 'inherit', # inherit | default | random
38 'mutable' => '1', # 0 | 1 # never usable
39 %options
40 );
41 7 ▶ return $attrs{$attr} if exists $attrs{$attr}; # check caller
Branch: 1 branch
BranchTrueFalseTotal
if exists $attrs{$attr} 0 7 7
42 7 ▶ my $coopRef = ($attrs{temperament} eq 'cooperative' or ($attrs{temperament} eq 'random' and int(rand(2)) ) )? undef:'';
Branch: 1 branch
BranchTrueFalseTotal
$attrs{'temperament'} eq 'cooperative' || $attrs{'temperament'} eq 'random' && int rand 2 ? : 5 2 7
Condition50%3/6
$attrs{"temperament"} eq "cooperative" or $attrs{"temperament"} eq "random" and int rand 2
l!l&&r!l&&!r
502
$attrs{"temperament"} eq "random" and int rand 2
!ll&&!rl&&r
200
MC/DC33%1/3
$attrs{"temperament"} eq "cooperative" or $attrs{"temperament"} eq "random" and int rand 2
$attrs{"temperament"} eq "cooperative" $attrs{"temperament"} eq "random" int rand 2
Truth table50%2/4
A or B and C
A= $attrs{"temperament"} eq "cooperative"B= $attrs{"temperament"} eq "random"C= int rand 2
ABCresult
1XX1
0111
00X0
0100
43 my %overload = (
44 0 ▶ '0+' => sub {return ($_[0]= defined $coopRef?die:0);},
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined $coopRef ? : 0 0 0
45 3 ▶ '""' => sub {return ($_[0]= defined $coopRef?die:'');}, # todo: include temperament
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $coopRef ? : 1 2 3
46 1 ▶ '@{}' => sub {return ($_[0]=$coopRef // []);}, # todo: include temperament
Subroutine __ANON__: called CC=2 SCAR=7.6
Condition50%1/2
$coopRef // []
l!l
01
MC/DC0%0/1
$coopRef // []
$coopRef
Truth table50%1/2
A
A= $coopRef
Aresult
11
00
47 2 ▶ '%{}' => sub {return ($_[0]=$coopRef // {});}, # todo: include temperament
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$coopRef // {}
l!l
11
MC/DC100%1/1
$coopRef // {}
$coopRef
Truth table100%2/2
A
A= $coopRef
Aresult
11
00
48 1 ▶ '${}' => sub {return ($_[0]=$coopRef // \0);}, # todo: include temperament
Subroutine __ANON__: called CC=2 SCAR=7.6
Condition50%1/2
$coopRef // \0
l!l
01
MC/DC0%0/1
$coopRef // \0
$coopRef
Truth table50%1/2
A
A= $coopRef
Aresult
11
00
49 0 ▶ '*{}' => sub {return ($_[0]=$coopRef // \*{''});}, # todo: include temperament
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$coopRef // \*{"";}
l!l
00
MC/DC0%0/1
$coopRef // \*{"";}
$coopRef
Truth table0%0/2
A
A= $coopRef
Aresult
11
00
50 7 );
51 7 return $overload{$attr};
52 8 };
53 8 bless $self, $class;
54 }
55  
56 =head1 SYNOPSIS
57  
58 A newly-created Acme::Cat::Schroedinger could be anything. It could be cooperative, and be anything you want it to be. It could be perverse and will never be what you want it to be. Or it could behave like the original Schroedinger's Cat and its behaviour will be, for all intents and purposes, unknowable until you interact with it.
59  
60 my $cat = Acme::Cat::Schroedinger->new();
61 print %{$cat}; # The cat is now an empty hashref, and does not die.
62
63 # or...
64 my $cat = Acme::Cat::Schroedinger->new(temperament=>'perverse');
65 print %{$cat}; # The cat is guaranteed not to be a hashref (or anything else you expect it to be), and thus will die.
66  
67 # or...
68 my $cat = Acme::Cat::Schroedinger->new(temperament=>'random');
69 print %{$cat}; # May or may not die, the only way of knowing is running the code.
70  
71 =head1 DESCRIPTION
72  
73 The Acme::Cat::Schroedinger can be 'observed' in various ways by being treated like a hashref or an arrayref or a string.
74  
75 Note that once you have observed the cat, it typically ceases to be a cat: the experiment is no longer repeatable.
76  
77 =head2 METHOD new
78  
79 my $cat = Acme::Cat::Schroedinger->new();
80  
81 When you create the cat, it has the following properties:
82  
83 =head3 temperament = cooperative
84  
85 Allowed: C<cooperative|perverse|random>. Determines whether the cat always behaves the way you ask it to, never behaves the way you ask it to, or decides how to behave only when you ask it.
86  
87 =head1 BUGS
88  
89 If you're clever, you can work out that the object in question is a cat, and furthermore you might be able to work out its temperament, mutability, etc.
90  
91 =cut
92  
93 3 1;
↑ Summary