File Coverage

blib/lib/Text/vCard/Precisely/V3/Node/SocialProfile.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::V3::Node::SocialProfile;
2              
3 28     28   212 use Carp;
  28         78  
  28         2324  
4 28     28   228 use Encode;
  28         83  
  28         4777  
5              
6 28     28   207 use Moose;
  28         79  
  28         235  
7 28     28   174353 use Moose::Util::TypeConstraints;
  28         75  
  28         254  
8              
9             extends 'Text::vCard::Precisely::V3::Node';
10              
11             has name => ( is => 'ro', default => 'X-SOCIALPROFILE', isa => 'Str' );
12             has content => ( is => 'rw', isa => 'Str', required => 1 );
13              
14             subtype 'SocialProfileType' => as 'Str' => where {
15             m/^(?:facebook|twitter|LinkedIn|flickr|myspace|sinaweibo|LINE|GitHub|Instagram|YouTube|Twitch)$/is
16             } => message {"The text you provided, $_, was not supported in 'SocialProfileType'"};
17             has types => ( is => 'rw', isa => 'SocialProfileType', required => 1 );
18              
19             has userid => ( is => 'rw', isa => 'Str' );
20              
21             subtype 'SocialProfileName' => as 'Str' => where { decode_utf8($_) =~ m/^[\w\s]+$/s }
22             => message {"The text you provided, $_, was not supported in 'SocialProfileName'"};
23             coerce 'SocialProfileName', from 'Str', via { encode_utf8($_) };
24             has displayname => ( is => 'rw', isa => 'SocialProfileName', coerce => 1 );
25              
26             override 'as_string' => sub {
27             my ($self) = @_;
28             my @lines;
29             push @lines, $self->name() || croak "Empty name";
30             push @lines, 'ALTID=' . $self->altID() if $self->can('altID') and $self->altID();
31             push @lines, 'PID=' . join ',', @{ $self->pid() } if $self->can('pid') and $self->pid();
32             push @lines, 'TYPE=' . $self->types() || croak "Empty types";
33             push @lines, 'X-USERID=' . $self->userid() if defined $self->userid() and $self->userid();
34             push @lines, 'X-DISPLAYNAME=' . $self->displayname()
35             if defined $self->displayname()
36             and $self->displayname();
37              
38             my $string = join( ';', @lines ) . ':' . $self->content();
39             return $self->fold( $string, -force => 1 );
40             };
41              
42             __PACKAGE__->meta->make_immutable;
43 28     28   71887 no Moose;
  28         74  
  28         184  
44              
45             1;