Struct/YearMonth.pm

filter: Statementstmt 100% 32 / 32 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 100% 46 / 46 CC 3 SCAR 4.7
CC
3
Cov
100%
obj2struct
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.6
« Struct/User.pm ↑ Summary Struct.pm »
1 package Toolforge::MixNMatch::Struct::YearMonth;
2  
3 8 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 8 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use Toolforge::MixNMatch::Object::YearMonth;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 8 Readonly::Array our @EXPORT_OK => qw(obj2struct struct2obj);
12  
13 8 our $VERSION = 0.04;
14  
15 5 ▶sub obj2struct {
Subroutine obj2struct: called CC=3 SCAR=11.0
Pod documented
16 5 my $obj = shift;
17  
18 5 ▶ if (! defined $obj) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $obj) 1 4 5
19 1 err "Object doesn't exist.";
20 }
21 4 ▶ if (! $obj->isa('Toolforge::MixNMatch::Object::YearMonth')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj->isa("Toolforge::MixNMatch::Object::YearMonth")) 1 3 4
22 1 err "Object isn't 'Toolforge::MixNMatch::Object::YearMonth'.";
23 }
24  
25 3 my $struct_hr = {
26 'cnt' => $obj->count,
27 'ym' => $obj->year.(sprintf '%02d', $obj->month),
28 };
29  
30 3 return $struct_hr;
31 }
32  
33 3 ▶sub struct2obj {
Subroutine struct2obj: called CC=1 SCAR=0.0
Pod documented
34 3 my $struct_hr = shift;
35  
36 3 my ($year, $month) = $struct_hr->{'ym'} =~ m/^(\d{4})(\d{2})$/ms;
37 my $obj = Toolforge::MixNMatch::Object::YearMonth->new(
38 3 'count' => $struct_hr->{'cnt'},
39 'month' => int($month),
40 'year' => $year,
41 );
42  
43 3 return $obj;
44 }
45  
46 8 1;
47  
48 __END__
« Struct/User.pm ↑ Summary Struct.pm »