File Coverage

blib/lib/Text/vCard/Precisely.pm
Criterion Covered Total %
statement 14 14 100.0
branch 2 2 100.0
condition n/a
subroutine 4 4 100.0
pod 0 1 0.0
total 20 21 95.2


line stmt bran cond sub pod time code
1             package Text::vCard::Precisely;
2              
3             our $VERSION = '0.26';
4              
5 2     2   1180 use Moose;
  2         414896  
  2         14  
6 2     2   13863 use Moose::Util::TypeConstraints;
  2         5  
  2         19  
7              
8             extends 'Text::vCard::Precisely::V3';
9              
10             enum 'Version' => [qw( 3.0 4.0 )];
11             has version => ( is => 'ro', isa => 'Version', default => '3.0', required => 1 );
12              
13             sub BUILD {
14 10     10 0 21 my $self = shift;
15 10 100       337 return Text::vCard::Precisely::V3->new(@_) unless $self->version() eq '4.0';
16              
17 1         656 require Text::vCard::Precisely::V4;
18 1         34 our @ISA = 'Text::vCard::Precisely::V4';
19 1         40 return Text::vCard::Precisely::V4->new(@_);
20             }
21              
22             __PACKAGE__->meta->make_immutable;
23 2     2   4404 no Moose;
  2         5  
  2         10  
24              
25             1;
26              
27             __END__
28              
29             =encoding UTF8
30              
31             =head1 NAME
32              
33             Text::vCard::Precisely - Read, Write and Edit the vCards 3.0 and/or 4.0 precisely
34              
35             =head1 SYNOPSIS
36              
37             my $vc = Text::vCard::Precisely->new();
38             # Or now you can write like below if you want to use 4.0:
39             my $vc4 = Text::vCard::Precisely->new( version => '4.0' );
40             #or $vc4 = Text::vCard::Precisely::V4->new();
41              
42             $vc->n([ 'Gump', 'Forrest', , 'Mr', '' ]);
43             $vc->fn( 'Forrest Gump' );
44              
45             use GD;
46             use MIME::Base64;
47             my $gd = GD::Image->new( 100, 100 );
48             my $black = $gd->colorAllocate( 0, 0, 0 );
49             $gd->rectangle( 0, 0, 99, 99, $black );
50              
51             my $img = $gd->png();
52             my $base64 = MIME::Base64::encode($img);
53              
54             $vc->photo([
55             { content => 'https://avatars2.githubusercontent.com/u/2944869?v=3&s=400', media_type => 'image/jpeg' },
56             { content => $img, media_type => 'image/png' }, # Now you can set a binary image directly
57             { content => $base64, media_type => 'image/png' }, # Also accept the text encoded in Base64
58             ]);
59              
60             $vc->org('Bubba Gump Shrimp Co.'); # Now you can set/get org!
61              
62             $vc->tel({ content => '+1-111-555-1212', types => ['work'], pref => 1 });
63              
64             $vc->email({ content => 'forrestgump@example.com', types => ['work'] });
65              
66             $vc->adr( {
67             types => ['work'],
68             pobox => '109',
69             extended => 'Shrimp Bld.',
70             street => 'Waters Edge',
71             city => 'Baytown',
72             region => 'LA',
73             post_code => '30314',
74             country => 'United States of America',
75             });
76              
77             $vc->url({ content => 'https://twitter.com/worthmine', types => ['twitter'] }); # for URL param
78              
79             print $vc->as_string();
80              
81             =head1 DESCRIPTION
82              
83             A vCard is a digital business card.
84             vCard and L<Text::vFile::asData> provides an API for parsing vCards
85              
86             This module is forked from L<Text::vCard>
87             because some reason below:
88              
89             =over
90              
91             =item
92              
93             Text::vCard B<doesn't provide> full methods based on L<RFC2426|https://tools.ietf.org/html/rfc2426>
94              
95             =item
96              
97             Mac OS X and iOS can't parse vCard4.0 with UTF-8 precisely. they cause some Mojibake
98              
99             =item
100              
101             Android 4.4.x can't parse vCard4.0
102              
103             =back
104              
105             To handle an address book with several vCard entries in it, start with
106             L<Text::vFile::asData> and then come back to this module.
107              
108             Note that the vCard RFC requires C<VERSION> and C<FN>. This module does not check or warn yet if these conditions have not been met
109              
110             =head1 Constructors
111              
112             =head2 load_hashref($HashRef)
113              
114             Accepts a HashRef that looks like below:
115              
116             my $hashref = {
117             N => [ 'Gump', 'Forrest', '', 'Mr.', '' ],
118             FN => 'Forrest Gump',
119             SORT_STRING => 'Forrest Gump',
120             ORG => 'Bubba Gump Shrimp Co.',
121             TITLE => 'Shrimp Man',
122             PHOTO => { media_type => 'image/gif', content => 'http://www.example.com/dir_photos/my_photo.gif' },
123             TEL => [
124             { types => ['WORK','VOICE'], content => '(111) 555-1212' },
125             { types => ['HOME','VOICE'], content => '(404) 555-1212' },
126             ],
127             ADR =>[{
128             types => ['work'],
129             pref => 1,
130             extended => 100,
131             street => 'Waters Edge',
132             city => 'Baytown',
133             region => 'LA',
134             post_code => '30314',
135             country => 'United States of America'
136             },{
137             types => ['home'],
138             extended => 42,
139             street => 'Plantation St.',
140             city => 'Baytown',
141             region => 'LA',
142             post_code => '30314',
143             country => 'United States of America'
144             }],
145             URL => 'http://www.example.com/dir_photos/my_photo.gif',
146             EMAIL => 'forrestgump@example.com',
147             REV => '2008-04-24T19:52:43Z',
148             };
149              
150             =head2 load_file($file_name)
151              
152             Accepts a file name
153              
154             =head2 load_string($vCard)
155              
156             Accepts a vCard string
157              
158             =head1 METHODS
159              
160             =head2 as_string()
161              
162             Returns the vCard as a string.
163             You have to use C<Encode::encode_utf8()> if your vCard is written in utf8
164              
165             =head2 as_file($filename)
166              
167             Write data in vCard format to $filename.
168             Dies if not successful
169              
170             =head1 SIMPLE GETTERS/SETTERS
171              
172             These methods accept and return strings
173              
174             =head2 version()
175              
176             returns Version number of the vcard.
177             Defaults to B<'3.0'> and this method is B<READONLY>
178              
179             =head2 rev()
180              
181             To specify revision information about the current vCard
182              
183             =head2 sort_string()
184              
185             To specify the family name, given name or organization text to be used for
186             national-language-specific sorting of the C<FN>, C<N> and C<ORG>.
187              
188             B<This method is DEPRECATED in vCard4.0> Use C<SORT-AS> param instead of it.
189              
190             =head1 COMPLEX GETTERS/SETTERS
191              
192             They are based on Moose with coercion.
193             So these methods accept not only ArrayRef[HashRef] but also ArrayRef[Str],
194             single HashRef or single Str.
195              
196             Read source if you were confused
197              
198             =head2 n()
199              
200             To specify the components of the name of the object the vCard represents
201              
202             =head2 tel()
203              
204             Accepts/returns an ArrayRef that looks like:
205              
206             [
207             { type => ['work'], content => '651-290-1234', preferred => 1 },
208             { type => ['home'], content => '651-290-1111' },
209             ]
210              
211             After version 0.18, B<content will not be validated as phone numbers>
212             All I<Str> type is accepted.
213              
214             So you have to validate phone numbers with your way.
215              
216             =head2 adr(), address()
217              
218             Accepts/returns an ArrayRef that looks like:
219              
220             [
221             { types => ['work'], street => 'Main St', pref => 1 },
222             { types => ['home'],
223             pobox => 1234,
224             extended => 'asdf',
225             street => 'Army St',
226             city => 'Desert Base',
227             region => '',
228             post_code => '',
229             country => 'USA',
230             pref => 2,
231             },
232             ]
233              
234             =head2 email()
235              
236             Accepts/returns an ArrayRef that looks like:
237              
238             [
239             { type => ['work'], content => 'bbanner@ssh.secret.army.mil' },
240             { type => ['home'], content => 'bbanner@timewarner.com', pref => 1 },
241             ]
242              
243             or accept the string as email like below
244              
245             'bbanner@timewarner.com'
246              
247             =head2 url()
248              
249             Accepts/returns an ArrayRef that looks like:
250              
251             [
252             { content => 'https://twitter.com/worthmine', types => ['twitter'] },
253             { content => 'https://github.com/worthmine' },
254             ]
255              
256             or accept the string as URL like below
257              
258             'https://github.com/worthmine'
259              
260             =head2 photo(), logo()
261              
262             Accepts/returns an ArrayRef of URLs or Images:
263             Even if they are raw image binary or text encoded in Base64, it does not matter
264              
265             B<Attention!> Mac OS X and iOS B<ignore> the description beeing URL
266              
267             use Base64 encoding or raw image binary if you have to show the image you want
268              
269             =head2 note()
270              
271             To specify supplemental information or a comment that is associated with the vCard
272              
273             =head2 org(), title(), role(), categories()
274              
275             To specify additional information for your jobs
276              
277             =head2 fn(), full_name(), fullname()
278              
279             A person's entire name as they would like to see it displayed
280              
281             =head2 nickname()
282              
283             To specify the text corresponding to the nickname of the object the vCard represents
284              
285             =head2 geo()
286              
287             To specify information related to the global positioning of the object the vCard represents
288              
289             =head2 key()
290              
291             To specify a public key or authentication certificate associated with the object that the vCard represents
292              
293             =head2 label()
294              
295             ToDo: because B<It's DEPRECATED in vCard4.0>
296              
297             To specify the formatted text corresponding to delivery address of the object the vCard represents
298              
299             =head2 uid()
300              
301             To specify a value that represents a globally unique identifier corresponding to
302             the individual or resource associated with the vCard
303              
304             =head2 tz(), timezone()
305              
306             Both are same method with Alias
307              
308             To specify information related to the time zone of the object the vCard represents
309              
310             utc-offset format is NOT RECOMMENDED from vCard4.0
311              
312             C<TZ> can be a URL, but there is no document in
313             L<RFC2426|https://tools.ietf.org/html/rfc2426>
314             or L<RFC6350|https://tools.ietf.org/html/rfc6350>
315              
316             So it just supports some text values
317              
318             =head2 bday(), birthday()
319              
320             Both are same method with Alias
321              
322             To specify the birth date of the object the vCard represents
323              
324             =head2 prodid()
325              
326             To specify the identifier for the product that created the vCard object
327              
328             =head2 source()
329              
330             To identify the source of directory information contained in the content type
331              
332             =head2 sound()
333              
334             To specify a digital sound content information that annotates some aspect of the vCard
335              
336             This property is often used to specify the proper pronunciation of
337             the name property value of the vCard
338              
339             =head2 socialprofile()
340              
341             There is no documents about C<X-SOCIALPROFILE> in RFC but it works in iOS and Mac OS X!
342              
343             I don't know well about in Android or Windows. Somebody please feedback me
344              
345             =head2 label()
346              
347             B<It's DEPRECATED in vCard4.0> You can use this method Just ONLY in vCard3.0
348              
349             =head1 For operating files with multiple vCards
350              
351             See L<Text::vCard::Precisely::Multiple>
352              
353             =head1 aroud UTF-8
354              
355             If you want to send precisely the vCard with UTF-8 characters to the B<ALMOST>
356             of smartphones, Use 3.0
357              
358             It seems to be TOO EARLY to use 4.0
359              
360             =head1 for under perl-5.12.5
361              
362             This module uses C<\P{ascii}> in regexp so You have to use 5.12.5 and later
363              
364             =head1 SEE ALSO
365              
366             =over
367              
368             =item
369              
370             L<RFC 2426|https://tools.ietf.org/html/rfc2426>
371              
372             =item
373              
374             L<RFC 2425|https://tools.ietf.org/html/rfc2425>
375              
376             =item
377              
378             L<RFC 6350|https://tools.ietf.org/html/rfc6350>
379              
380             =item
381              
382             L<Text::vCard::Precisely::Multiple>
383              
384             =item
385              
386             L<Text::vFile::asData>
387              
388             =back
389              
390             =head1 AUTHOR
391              
392             Yuki Yoshida(L<worthmine|https://github.com/worthmine>)
393              
394             =head1 LICENSE
395              
396             This is free software; you can redistribute it and/or modify it under the same terms as Perl.