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   8086 use Carp;
  28         70  
  28         1989  
4              
5 28     28   182 use Moose;
  28         66  
  28         191  
6 28     28   177140 use Moose::Util::TypeConstraints;
  28         73  
  28         233  
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             push 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   70399 no Moose;
  28         85  
  28         156  
49              
50             1;