blib/lib/Array/Autojoin.pm

filter: Statementstmt 93.3% 28 / 30 Branchbran 75.0% 3 / 4 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 91.3% 42 / 46 CC 5 SCAR 6.3
CC
5
Cov
92%
__ANON__
3.0
__ANON__
2.2
__ANON__
2.0
CRAP 1.9
↑ Summary
1  
2 2 require 5;
3 package Array::Autojoin;
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use vars qw($VERSION @ISA @EXPORT);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 # Time-stamp: "2004-12-29 19:47:36 AST"
7 2 $VERSION = '0.03';
8 2 require Exporter;
9 2 @ISA = ('Exporter');
10 2 @EXPORT = ('mkarray');
11  
12 3 ▶sub mkarray { bless [@_], 'Array::Autojoin::X' }
Subroutine mkarray: called CC=1 SCAR=0.0
Pod undocumented
13  
14 {
15 # And then the class for that:
16  
17 package Array::Autojoin::X;
18  
19 # TODO: Hmm, methods for *=, +=, etc?
20  
21 2 ▶ use overload(
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 8 ▶ '""' => sub { join ', ', @{$_[0]}},
Subroutine __ANON__: called CC=1 SCAR=0.0
24  
25 8 ▶ '0+' => sub {0 + ( $_[0][0] || 0 ) },
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$_[0][0] || 0
l!l
71
MC/DC100%1/1
$_[0][0] || 0
$_[0][0]
Truth table100%2/2
A
A= $_[0][0]
Aresult
11
00
26 # stringifies and then just numerifies, but feh.
27  
28 'fallback' => 1, # turn on cleverness
29  
30 2 ▶ 'bool', => sub { # true iff there's any true items in it
Subroutine __ANON__: called CC=3 SCAR=11.0
31 2 ▶ for (@{$_[0]}) { return 1 if $_ };
Branch: 1 branch
BranchTrueFalseTotal
if $_ 1 3 4
32 1 return '';
33 },
34  
35 1 ▶ '.=' => sub { # sure, why not.
Subroutine __ANON__: called CC=2 SCAR=7.9
36 0 ▶ if(@{$_[0]}) { $_[0][-1] .= $_[1] } else { push @{$_[0]}, $_[1] }
Branch: 1 branch
BranchTrueFalseTotal
if (@{$_[0];}) { } 1 0 1
37 1 $_[0];
38 }, # but can't overload ||= or the like
39  
40 2 );
41 }
42  
43 2 1;
44  
45 __END__
↑ Summary