File Coverage

blib/lib/Text/vCard/Precisely/V3/Node/URL.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::URL;
2              
3 28     28   246 use Carp;
  28         70  
  28         2672  
4 28     28   249 use URI;
  28         91  
  28         920  
5              
6 28     28   183 use Moose;
  28         73  
  28         337  
7 28     28   205581 use Moose::Util::TypeConstraints;
  28         112  
  28         387  
8              
9             extends 'Text::vCard::Precisely::V3::Node';
10              
11             has name => ( is => 'ro', default => 'URL', isa => 'Str' );
12             has types => ( is => 'rw', isa => 'Types', coerce => 1 );
13              
14             subtype 'URL' => as 'Str';
15             coerce 'URL' => from 'Str' => via { [ URI->new($_)->as_string() ] };
16             has content => ( is => 'ro', default => '', isa => 'URL', coerce => 1 );
17              
18             override 'as_string' => sub {
19             my ($self) = @_;
20             my @lines;
21             push @lines, $self->name() || croak "Empty name";
22             push @lines, 'ALTID=' . $self->altID() if $self->can('altID') and $self->altID();
23             push @lines, 'PID=' . join ',', @{ $self->pid() } if $self->can('pid') and $self->pid();
24             push @lines, 'TYPE=' . join( ',', map { uc $_ } @{ $self->types() } )
25             if ref $self->types() eq 'ARRAY' and $self->types()->[0];
26              
27             my $string = join( ';', @lines ) . ':' . $self->content();
28             return $self->fold( $string, -force => 1 );
29             };
30              
31             __PACKAGE__->meta->make_immutable;
32 28     28   72423 no Moose;
  28         91  
  28         202  
33              
34             1;