blib/lib/Class/MakeMethods/Emulator/Struct.pm

filter: Statementstmt 83.7% 36 / 43 Branchbran 72.2% 13 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 79.4% 54 / 68 CC 10 SCAR 17.8
CC
10
Cov
80%
struct
9.4
import
3.0
_usage_error
2.0
CRAP 5.9
« blib/lib/Class/MakeMethods/Emulator/Inheritable.pm ↑ Summary blib/lib/Class/MakeMethods/Attribute.pm »
1 package Class::MakeMethods::Emulator::Struct;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use Class::MakeMethods;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use vars qw(@ISA @EXPORT);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 require Exporter;
9 2 push @ISA, qw(Exporter);
10 2 @EXPORT = qw(struct);
11  
12 5 ▶sub import {
Subroutine import: called CC=3 SCAR=11.0
13 5 my $self = shift;
14
15 5 ▶ if ( @_ == 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 0) { } 3 2 5
elsif (@_ == 1) { } 1 1 2
16 3 $self->export_to_level( 1, $self, @EXPORT );
17 } elsif ( @_ == 1 ) {
18 1 $self->export_to_level( 1, $self, @_ );
19 } else {
20 1 &struct;
21 }
22 }
23  
24 ########################################################################
25  
26 2 my %type_map = (
27 '$' => 'scalar',
28 '@' => 'array',
29 '%' => 'hash',
30 '_' => 'object',
31 );
32  
33 4 ▶sub struct {
Subroutine struct: called CC=8 SCAR=22.4
Pod undocumented
34 4 my ($class, @decls);
35 4 my $base_type = ref $_[1] ;
36 4 ▶ if ( $base_type eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($base_type eq 'HASH') { } 2 2 4
elsif ($base_type eq 'ARRAY') { } 0 2 2
37 2 $base_type = 'Standard::Hash';
38 2 $class = shift;
39 2 @decls = %{shift()};
40 2 ▶ _usage_error() if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
41 }
42 elsif ( $base_type eq 'ARRAY' ) {
43 0 $base_type = 'Standard::Array';
44 0 $class = shift;
45 0 @decls = @{shift()};
46 0 ▶ _usage_error() if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
47 }
48 else {
49 2 $base_type = 'Standard::Array';
50 2 $class = (caller())[0];
51 2 @decls = @_;
52 }
53 4 ▶ _usage_error() if @decls % 2 == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @decls % 2 == 1 0 4 4
54
55 4 my @rewrite;
56 4 ▶ while ( scalar @decls ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @decls) 13 4 17
57 13 my ($name, $type) = splice(@decls, 0, 2);
58 push @rewrite, $type_map{$type}
59 ? ( $type_map{$type} => { 'name'=>$name, auto_init=>1 } )
60 13 ▶ : ( $type_map{'_'} => { 'name'=>$name, 'class'=>$type, auto_init=>1 } );
Branch: 1 branch
BranchTrueFalseTotal
$type_map{$type} ? : 10 3 13
61 }
62 Class::MakeMethods->make(
63 4 -TargetClass => $class,
64 -MakerClass => $base_type,
65 "new" => 'new',
66 @rewrite
67 );
68 }
69  
70 0 ▶sub _usage_error {
Subroutine _usage_error: not called CC=1 SCAR=6.9
71 0 require Carp;
72 0 Carp::confess "struct usage error";
73 }
74  
75 ########################################################################
76  
77 2 1;
78  
79 __END__
« blib/lib/Class/MakeMethods/Emulator/Inheritable.pm ↑ Summary blib/lib/Class/MakeMethods/Attribute.pm »