File Coverage

blib/lib/Class/Business/DK/Phonenumber.pm
Criterion Covered Total %
statement 46 50 92.0
branch 19 22 86.3
condition 1 3 33.3
subroutine 9 9 100.0
pod 3 3 100.0
total 78 87 89.6


line stmt bran cond sub pod time code
1             package Class::Business::DK::Phonenumber;
2              
3 4     4   3042 use strict;
  4         7  
  4         130  
4 4     4   18 use warnings;
  4         4  
  4         155  
5 4     4   17 use vars qw($VERSION);
  4         5  
  4         214  
6 4     4   20 use Carp qw(croak);
  4         6  
  4         295  
7             use Business::DK::Phonenumber
8 4     4   2045 qw(validate render validate_template DEFAULT_TEMPLATE DK_PREFIX TRUE FALSE);
  4         8  
  4         445  
9              
10             $VERSION = '0.10';
11              
12             ## no critic (ValuesAndExpressions::ProhibitEmptyQuotes, ValuesAndExpressions::ProhibitInterpolationOfLiterals)
13 4     4   22 use overload "" => \&render;
  4         6  
  4         31  
14              
15             sub new {
16 7     7 1 4040 my ( $class, $params ) = @_;
17              
18 7   33     35 my $self = bless {
19             phonenumber => 0,
20             template => DEFAULT_TEMPLATE,
21             prefix => DK_PREFIX,
22             },
23             $class || ref $class;
24              
25 7 100       19 if ( $params->{phonenumber} ) {
26             $self->phonenumber( $params->{phonenumber} )
27 6 100       15 or croak
28             "phonenumber >$params->{phonenumber}< not in recognisable format";
29             } else {
30 1         10 croak 'phonenumber parameter is mandatory';
31             }
32              
33 5 100       17 if ( $params->{template} ) {
34             $self->template( $params->{template} )
35 1 50       2 or croak
36             "template >$params->{template}< not in recognisable format";
37             }
38              
39 5         13 $self->{prefix} = $params->{prefix};
40              
41 5         24 return $self;
42             }
43              
44             sub phonenumber {
45 12     12 1 17 my ( $self, $phonenumber, $template ) = @_;
46              
47 12 100       23 if ($phonenumber) {
48              
49 8         97 my $tmp_phonenumber = $self->{phonenumber};
50              
51 8 100       29 if ( validate($phonenumber) ) {
52 7         25 $self->{phonenumber} = $phonenumber;
53              
54 7 50       15 if ( $self->template($template) ) {
55 7         53 return TRUE;
56             } else {
57 0         0 $self->{phonenumber} = $tmp_phonenumber;
58              
59 0         0 croak "template >$template< not in recognisable format";
60             }
61              
62 0         0 return TRUE;
63             } else {
64 1         13 return FALSE;
65             }
66             } else {
67 4 100       7 if ($template) {
68 1 50       4 if ( $self->validate_template($template) ) {
69 1         3 return $self->render( undef, $template );
70             } else {
71 0         0 croak "template >$template< not in recognisable format";
72             }
73             } else {
74 3         7 return $self->render();
75             }
76             }
77             }
78              
79             sub template {
80 12     12 1 52 my ( $self, $template ) = @_;
81              
82 12 100       23 if ($template) {
83 4 100       12 if ( $self->validate_template($template) ) {
84 3         4 $self->{template} = $template;
85 3         8 return TRUE;
86             } else {
87 1         3 return FALSE;
88             }
89             } else {
90 8         29 return $self->{template};
91             }
92             }
93              
94             1;
95              
96             __END__