File Coverage

blib/lib/Text/vCard/Precisely/V4/Node/Member.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::Member;
2              
3 14     14   101 use Carp;
  14         29  
  14         975  
4 14     14   83 use Moose;
  14         29  
  14         93  
5 14     14   83584 use Moose::Util::TypeConstraints;
  14         35  
  14         115  
6              
7             extends 'Text::vCard::Precisely::V4::Node';
8              
9             has name => ( is => 'ro', default => 'MEMBER', isa => 'Str' );
10             has content => ( is => 'ro', default => '', isa => 'Str' );
11              
12             subtype 'MemberType' => as 'Str' => where {
13             m/^(?:contact|acquaintance|friend|met|co-worker|colleague|co-resident|neighbor|child|parent|sibling|spouse|kin|muse|crush|date|sweetheart|me|agent|emergency)$/is;
14              
15             # it needs tests
16             } => message {"The text you provided, $_, was not supported in 'MemberType'"};
17             has types => ( is => 'rw', isa => 'ArrayRef[MemberType]', default => sub { [] } );
18              
19             override 'as_string' => sub {
20             my ($self) = @_;
21             my @lines;
22             push @lines, $self->name() || croak "Empty name";
23             push @lines, 'ALTID=' . $self->altID() if $self->altID();
24             push @lines, 'PID=' . join ',', @{ $self->pid() } if $self->pid();
25             push @lines, 'TYPE="' . join( ',', map {uc} @{ $self->types() } ) . '"'
26             if ref $self->types() eq 'ARRAY' and $self->types()->[0];
27             push @lines, 'PREF=' . $self->pref() if $self->pref();
28              
29             my $string = join( ';', @lines ) . ':' . $self->_escape( $self->content() );
30             return $self->fold($string);
31             };
32              
33             __PACKAGE__->meta->make_immutable;
34 14     14   33094 no Moose;
  14         36  
  14         80  
35              
36             1;