File Coverage

blib/lib/Text/vCard/Precisely/V4/Node/Tel.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package Text::vCard::Precisely::V4::Node::Tel;
2              
3 14     14   98 use Carp;
  14         34  
  14         1043  
4              
5 14     14   84 use Moose;
  14         31  
  14         102  
6 14     14   86071 use Moose::Util::TypeConstraints;
  14         328  
  14         124  
7              
8             extends qw|Text::vCard::Precisely::V3::Node::Tel Text::vCard::Precisely::V4::Node|;
9              
10             # to validate phone numbers is too difficult for me
11             #subtype 'v4Tel'
12             # => as 'Str'
13             # => where { m/^(?:tel:)?(?:[+]?\d{1,2}|\d*)[\(\s\-]?\d{1,3}[\)\s\-]?[\s]?\d{1,3}[\s\-]?\d{3,4}$/s }
14             # => message { "The Number you provided, $_, was not supported in Tel" };
15             has content => ( is => 'ro', default => '', isa => 'Str' );
16              
17             override 'as_string' => sub {
18             my ($self) = @_;
19             my @lines;
20             push @lines, $self->name() || croak "Empty name";
21             push @lines, 'VALUE=uri';
22             push @lines, 'ALTID=' . $self->altID() if $self->altID();
23             push @lines, 'PID=' . join ',', @{ $self->pid() } if $self->pid();
24             push @lines, 'TYPE="' . join( ',', map {uc} grep {length} @{ $self->types() } ) . '"'
25             if ref $self->types() eq 'ARRAY' and $self->types()->[0];
26              
27             #( my $content = $self->content() ) =~ s/^\s+//s; # remove top space
28             #$content =~ s/^tel:\(?//s; # remove tel: once
29             #$content =~ s/(?:(?!\A)\D|\()+/ /sg; # replace symbols to space
30             #$content =~ s/^\s+//s; # remove top space again
31             #my $string = join(';', @lines ) . ':tel:' . $content;
32             my $colon = $self->content() =~ /^tel:/ ? ':' : ':tel:';
33              
34             my $string = join( ';', @lines ) . $colon . $self->content();
35             return $self->fold( $string, -force => 1 );
36             };
37              
38             __PACKAGE__->meta->make_immutable;
39 14     14   30921 no Moose;
  14         36  
  14         76  
40              
41             1;