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   9407 use Carp;
  28         87  
  28         2330  
4 28     28   13262 use MIME::Base64;
  28         21566  
  28         1880  
5              
6 28     28   263 use Moose;
  28         93  
  28         277  
7 28     28   201603 use Moose::Util::TypeConstraints;
  28         85  
  28         355  
8 28     28   73224 use Data::Validate::URI qw(is_web_uri);
  28         701432  
  28         15739  
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   285 no Moose;
  28         77  
  28         269  
40              
41             1;