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   101 use Carp;
  14         31  
  14         1031  
4 14     14   6129 use URI;
  14         51640  
  14         408  
5              
6 14     14   94 use Moose;
  14         31  
  14         104  
7 14     14   90507 use Moose::Util::TypeConstraints;
  14         33  
  14         126  
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   34510 no Moose;
  14         31  
  14         79  
40              
41             1;