File Coverage

blib/lib/Text/vCard/Precisely/V3/Node/Image.pm
Criterion Covered Total %
statement 18 18 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 24 24 100.0


line stmt bran cond sub pod time code
1             package Text::vCard::Precisely::V3::Node::Image;
2              
3 28     28   7653 use Carp;
  28         69  
  28         1931  
4 28     28   11968 use MIME::Base64;
  28         18426  
  28         1597  
5              
6 28     28   212 use Moose;
  28         80  
  28         214  
7 28     28   179516 use Moose::Util::TypeConstraints;
  28         75  
  28         317  
8 28     28   65594 use Data::Validate::URI qw(is_web_uri);
  28         630862  
  28         13668  
9              
10             extends 'Text::vCard::Precisely::V3::Node';
11              
12             has name => ( is => 'rw', default => 'PHOTO', isa => 'Str', required => 1 );
13              
14             subtype 'Images' => as 'Str' => where {
15             is_web_uri($_)
16             or s/\s//g || 1 and #force remove spaces and returns
17             m!^([A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$!
18             } => message {"The Unvalid value you provided, $_, was not supported in 'Images'"};
19             coerce 'Images' => from 'Str' =>
20             via { is_web_uri($_) && return $_->as_string() or encode_base64( $_, "" ) };
21             has content => ( is => 'rw', isa => 'Images', required => 1, coerce => 1 );
22              
23             subtype 'Media_type' => as 'Str' => where {m|^image/(?:X-)?[a-zA-z0-9\-]+$|is}
24             => message {"The Text you provided, $_, was not supported in 'Media_type'"};
25             has media_type => ( is => 'rw', isa => 'Media_type' );
26              
27             override 'as_string' => sub {
28             my ($self) = @_;
29             my @lines;
30             push @lines, $self->name() || croak "Empty name";
31             push @lines, "TYPE=" . $self->media_type() if defined $self->media_type();
32             push @lines, "ENCODING=b" unless is_web_uri( $self->content() );
33              
34             my $string = join( ';', @lines ) . ':' . $self->content();
35             return $self->fold( $string, -force => 1 );
36             };
37              
38             __PACKAGE__->meta->make_immutable;
39 28     28   273 no Moose;
  28         72  
  28         277  
40              
41             1;