File Coverage

blib/lib/Text/vCard/Precisely/V4/Node/Related.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 20 20 100.0


line stmt bran cond sub pod time code
1             package Text::vCard::Precisely::V4::Node::Related;
2              
3 14     14   117 use Carp;
  14         34  
  14         1170  
4 14     14   6665 use URI;
  14         56863  
  14         449  
5              
6 14     14   111 use Moose;
  14         37  
  14         128  
7 14     14   96563 use Moose::Util::TypeConstraints;
  14         34  
  14         142  
8              
9             extends 'Text::vCard::Precisely::V4::Node';
10              
11             has name => ( is => 'ro', default => 'RELATED', isa => 'Str' );
12              
13             subtype 'RelatedType' => as 'Str' => where {
14             m/^(?:contact|acquaintance|friend|met|co-worker|colleague|co-resident|neighbor|child|parent|sibling|spouse|kin|muse|crush|date|sweetheart|me|agent|emergency)$/is;
15              
16             # it needs tests
17             } => message {"The text you provided, $_, was not supported in 'RelatedType'"};
18              
19             subtype 'RelatedTypes' => as 'ArrayRef[RelatedType]';
20             coerce 'RelatedTypes' => from 'RelatedType' => via { [$_] };
21             has types =>
22             ( is => 'rw', isa => 'RelatedTypes', default => sub { [] }, required => 1, coerce => 1 );
23              
24             override 'as_string' => sub {
25             my ($self) = @_;
26             my @lines;
27             push @lines, $self->name() || croak "Empty name";
28             push @lines, 'ALTID=' . $self->altID() if $self->altID();
29             push @lines, 'PID=' . join ',', @{ $self->pid() } if $self->pid();
30             push @lines, 'TYPE="' . join( ',', map { uc $_ } @{ $self->types() } ) . '"'
31             if ref $self->types() eq 'ARRAY' and $self->types()->[0];
32             push @lines, "MEDIATYPE=" . $self->media_type() if defined $self->media_type();
33              
34             my $string = join( ';', @lines ) . ':' . $self->content();
35             return $self->fold( $string, -force => 1 );
36             };
37              
38             __PACKAGE__->meta->make_immutable;
39 14     14   36349 no Moose;
  14         33  
  14         82  
40              
41             1;