File Coverage

blib/lib/Text/vCard/Precisely/V3/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::V3::Node::Tel;
2              
3 28     28   7083 use Carp;
  28         67  
  28         1869  
4              
5 28     28   181 use Moose;
  28         57  
  28         182  
6 28     28   170904 use Moose::Util::TypeConstraints;
  28         64  
  28         221  
7              
8             extends 'Text::vCard::Precisely::V3::Node';
9              
10             has name => ( is => 'ro', default => 'TEL', isa => 'Str' );
11              
12             # to validate phone numbers is too difficult for me
13             #subtype 'Tel'
14             # => as 'Str'
15             # => where { m/^(?:[+]?\d{1,2}|\d*)[\(\s\-]?\d{1,3}[\)\s\-]?[\s]?\d{1,4}[\s\-]?\d{3,4}$/s }
16             # => message { "The Number you provided, $_, was not supported in Tel" };
17             has content => ( is => 'rw', default => '', isa => 'Str' );
18              
19             has preferred => ( is => 'rw', default => 0, isa => 'Bool' );
20              
21             subtype 'TelType' => as 'Str' => where {
22             m/^(?:work|home|pref)$/is || #common
23             m/^(?:text|voice|fax|cell|video|pager|textphone)$/is # for tel
24             } => message {"The text you provided, $_, was not supported in 'TelType'"};
25             has types => ( is => 'rw', isa => 'ArrayRef[Maybe[TelType]]', default => sub { [] } );
26              
27             override 'as_string' => sub {
28             my ($self) = @_;
29             my @lines;
30             push @lines, $self->name() || croak "Empty name";
31             push @lines, 'ALTID=' . $self->altID() if $self->can('altID') and $self->altID();
32             push @lines, 'PID=' . join ',', @{ $self->pid() } if $self->can('pid') and $self->pid();
33              
34             my @types = map {uc} grep {length} @{ $self->types() };
35             push @types, 'PREF' if $self->preferred();
36             my $types = 'TYPE="' . join( ',', @types ) . '"' if @types;
37             push @lines, $types if $types;
38              
39             #( my $content = $self->content() ) =~ s/^ //s; # remove top space
40             #$content =~ s/(?:(?!\A)\D|\()+/ /sg; # replace symbols to space
41             #$content =~ s/^ //s; # remove top space again
42             #my $string = join(';', @lines ) . ':' . $content;
43             my $string = join( ';', @lines ) . ':' . $self->content();
44             return $self->fold( $string, -force => 1 );
45             };
46              
47             __PACKAGE__->meta->make_immutable;
48 28     28   69723 no Moose;
  28         76  
  28         147  
49              
50             1;