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   3782 use strict;
  4         8  
  4         251  
4 4     4   25 use warnings;
  4         8  
  4         153  
5 4     4   29 use vars qw($VERSION);
  4         8  
  4         235  
6 4     4   25 use Carp qw(croak);
  4         11  
  4         284  
7             use Business::DK::Phonenumber
8 4     4   2596 qw(validate render validate_template DEFAULT_TEMPLATE DK_PREFIX TRUE FALSE);
  4         12  
  4         471  
9              
10             $VERSION = '0.09';
11              
12             ## no critic (ValuesAndExpressions::ProhibitEmptyQuotes, ValuesAndExpressions::ProhibitInterpolationOfLiterals)
13 4     4   27 use overload "" => \&render;
  4         7  
  4         40  
14              
15             sub new {
16 7     7 1 5823 my ( $class, $params ) = @_;
17              
18 7   33     89 my $self = bless {
19             phonenumber => 0,
20             template => DEFAULT_TEMPLATE,
21             prefix => DK_PREFIX,
22             },
23             $class || ref $class;
24              
25 7 100       25 if ( $params->{phonenumber} ) {
26 6 100       20 $self->phonenumber( $params->{phonenumber} )
27             or croak
28             "phonenumber >$params->{phonenumber}< not in recognisable format";
29             } else {
30 1         18 croak 'phonenumber parameter is mandatory';
31             }
32              
33 5 100       555 if ( $params->{template} ) {
34 1 50       3 $self->template( $params->{template} )
35             or croak
36             "template >$params->{template}< not in recognisable format";
37             }
38              
39 5         12 $self->{prefix} = $params->{prefix};
40              
41 5         581 return $self;
42             }
43              
44             sub phonenumber {
45 12     12 1 23 my ( $self, $phonenumber, $template ) = @_;
46              
47 12 100       29 if ($phonenumber) {
48              
49 8         151 my $tmp_phonenumber = $self->{phonenumber};
50              
51 8 100       34 if ( validate($phonenumber) ) {
52 7         16 $self->{phonenumber} = $phonenumber;
53              
54 7 50       20 if ( $self->template($template) ) {
55 7         111 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         37 return FALSE;
65             }
66             } else {
67 4 100       10 if ($template) {
68 1 50       4 if ( $self->validate_template($template) ) {
69 1         5 return $self->render( undef, $template );
70             } else {
71 0         0 croak "template >$template< not in recognisable format";
72             }
73             } else {
74 3         12 return $self->render();
75             }
76             }
77             }
78              
79             sub template {
80 12     12 1 20 my ( $self, $template ) = @_;
81              
82 12 100       26 if ($template) {
83 4 100       16 if ( $self->validate_template($template) ) {
84 3         7 $self->{template} = $template;
85 3         12 return TRUE;
86             } else {
87 1         3 return FALSE;
88             }
89             } else {
90 8         546 return $self->{template};
91             }
92             }
93              
94             1;
95              
96             __END__