Struct/Catalog.pm

filter: Statementstmt 100% 55 / 55 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 100% 71 / 71 CC 7 SCAR 9.7
CC
7
Cov
100%
obj2struct
5.0
struct2obj
3.0
BEGIN
1.0
CRAP 2.6
↑ Summary Struct/User.pm »
1 package Toolforge::MixNMatch::Struct::Catalog;
2  
3 4 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Toolforge::MixNMatch::Object::Catalog;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Toolforge::MixNMatch::Struct::User;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Toolforge::MixNMatch::Struct::YearMonth;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 Readonly::Array our @EXPORT_OK => qw(obj2struct struct2obj);
14  
15 4 our $VERSION = 0.04;
16  
17 4 ▶sub obj2struct {
Subroutine obj2struct: called CC=5 SCAR=16.1
Pod documented
18 4 my $obj = shift;
19  
20 4 ▶ if (! defined $obj) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $obj) 1 3 4
21 1 err "Object doesn't exist.";
22 }
23 3 ▶ if (! $obj->isa('Toolforge::MixNMatch::Object::Catalog')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj->isa("Toolforge::MixNMatch::Object::Catalog")) 1 2 3
24 1 err "Object isn't 'Toolforge::MixNMatch::Object::Catalog'.";
25 }
26  
27 2 my $struct_hr = {
28 'type' => [{
29 'type' => $obj->type,
30 'cnt' => $obj->count,
31 }],
32 'user' => [],
33 'ym' => [],
34 };
35 2 foreach my $year_month (@{$obj->year_months}) {
36 2 push @{$struct_hr->{'ym'}},
37 Toolforge::MixNMatch::Struct::YearMonth::obj2struct($year_month);
38 }
39 2 foreach my $user (@{$obj->users}) {
40 2 push @{$struct_hr->{'user'}},
41 Toolforge::MixNMatch::Struct::User::obj2struct($user);
42 }
43  
44 2 return $struct_hr;
45 }
46  
47 2 ▶sub struct2obj {
Subroutine struct2obj: called CC=3 SCAR=11.0
Pod documented
48 2 my $struct_hr = shift;
49  
50 2 my $year_months = [];
51 2 foreach my $year_month_hr (@{$struct_hr->{'ym'}}) {
52 2 push @{$year_months}, Toolforge::MixNMatch::Struct::YearMonth::struct2obj($year_month_hr);
53 }
54 2 my $users = [];
55 2 foreach my $user_hr (@{$struct_hr->{'user'}}) {
56 2 push @{$users}, Toolforge::MixNMatch::Struct::User::struct2obj($user_hr);
57 }
58 my $obj = Toolforge::MixNMatch::Object::Catalog->new(
59 'count' => $struct_hr->{'type'}->[0]->{'cnt'},
60 2 'type' => $struct_hr->{'type'}->[0]->{'type'},
61 'users' => $users,
62 'year_months' => $year_months,
63 );
64  
65 2 return $obj;
66 }
67  
68 4 1;
69  
70 __END__
↑ Summary Struct/User.pm »