| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Text::vCard::Precisely::Multiple; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.26'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
133330
|
use Moose; |
|
|
1
|
|
|
|
|
494024
|
|
|
|
1
|
|
|
|
|
8
|
|
|
6
|
1
|
|
|
1
|
|
7750
|
use Moose::Util::TypeConstraints; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
2289
|
use Carp; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
79
|
|
|
9
|
1
|
|
|
1
|
|
682
|
use Text::vCard::Precisely; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
88
|
|
|
10
|
1
|
|
|
1
|
|
11
|
use Text::vFile::asData; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
9
|
|
|
11
|
|
|
|
|
|
|
my $vf = Text::vFile::asData->new(); |
|
12
|
1
|
|
|
1
|
|
77
|
use Path::Tiny; |
|
|
1
|
|
|
|
|
37
|
|
|
|
1
|
|
|
|
|
206
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
enum 'Version' => [qw( 3.0 4.0 )]; |
|
15
|
|
|
|
|
|
|
has version => ( is => 'ro', isa => 'Version', default => '3.0', required => 1 ); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
subtype 'vCards' => as 'ArrayRef[Text::vCard::Precisely]'; |
|
18
|
|
|
|
|
|
|
coerce 'vCards', from 'Text::vCard::Precisely', via { [$_] }; |
|
19
|
|
|
|
|
|
|
has options => ( |
|
20
|
|
|
|
|
|
|
traits => ['Array'], |
|
21
|
|
|
|
|
|
|
is => 'ro', |
|
22
|
|
|
|
|
|
|
isa => 'vCards', |
|
23
|
|
|
|
|
|
|
coerce => 1, |
|
24
|
|
|
|
|
|
|
default => sub { [] }, |
|
25
|
|
|
|
|
|
|
handles => { |
|
26
|
|
|
|
|
|
|
all_options => 'elements', |
|
27
|
|
|
|
|
|
|
add_option => 'push', |
|
28
|
|
|
|
|
|
|
clear_options => 'clear', |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
#map_options => 'map', |
|
31
|
|
|
|
|
|
|
#filter_options => 'grep', |
|
32
|
|
|
|
|
|
|
#find_option => 'first', |
|
33
|
|
|
|
|
|
|
#get_option => 'get', |
|
34
|
|
|
|
|
|
|
#join_options => 'join', |
|
35
|
|
|
|
|
|
|
count_options => 'count', |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#has_options => 'count', |
|
38
|
|
|
|
|
|
|
has_no_options => 'is_empty', |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
#sorted_options => 'sort', |
|
41
|
|
|
|
|
|
|
}, |
|
42
|
|
|
|
|
|
|
); |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
45
|
1
|
|
|
1
|
|
9
|
no Moose; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
7
|
|
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub load_arrayref { |
|
48
|
1
|
|
|
1
|
1
|
2821
|
my $self = shift; |
|
49
|
1
|
|
|
|
|
2
|
my $ref = shift; |
|
50
|
1
|
50
|
|
|
|
8
|
croak "Attribute must be an ArrayRef: $ref" unless ref($ref) eq 'ARRAY'; |
|
51
|
1
|
|
|
|
|
49
|
$self->clear_options(); |
|
52
|
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
4
|
foreach my $data (@$ref) { |
|
54
|
2
|
|
|
|
|
71
|
my $vc = Text::vCard::Precisely->new( version => $self->version() ); |
|
55
|
2
|
|
|
|
|
13
|
$self->add_option( $vc->load_hashref($data) ); |
|
56
|
|
|
|
|
|
|
} |
|
57
|
1
|
|
|
|
|
6
|
return $self; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub load_file { |
|
61
|
1
|
|
|
1
|
1
|
756
|
my $self = shift; |
|
62
|
1
|
|
|
|
|
4
|
my $filename = shift; |
|
63
|
1
|
50
|
|
|
|
59
|
open my $vcf, "<", $filename or croak "couldn't open vcf: $!"; |
|
64
|
1
|
|
|
|
|
64
|
my $objects = $vf->parse($vcf)->{'objects'}; |
|
65
|
1
|
|
|
|
|
5184
|
close $vcf; |
|
66
|
|
|
|
|
|
|
|
|
67
|
1
|
|
|
|
|
58
|
$self->clear_options(); |
|
68
|
1
|
|
|
|
|
4
|
foreach my $data (@$objects) { |
|
69
|
5
|
50
|
|
|
|
19
|
croak "$filename contains unvalid vCard data." unless $data->{'type'} eq 'VCARD'; |
|
70
|
5
|
|
|
|
|
177
|
my $vc = Text::vCard::Precisely->new( version => $self->version() ); |
|
71
|
5
|
|
|
|
|
26
|
my $hashref = $vc->_make_hashref($data); |
|
72
|
5
|
|
|
|
|
21
|
$self->add_option( $vc->load_hashref($hashref) ); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
1
|
|
|
|
|
39
|
return $self; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub as_string { |
|
78
|
2
|
|
|
2
|
1
|
241
|
my $self = shift; |
|
79
|
2
|
|
|
|
|
6
|
my $str = ''; |
|
80
|
2
|
|
|
|
|
100
|
foreach my $vc ( $self->all_options() ) { |
|
81
|
7
|
|
|
|
|
319
|
$str .= $vc->as_string(); |
|
82
|
|
|
|
|
|
|
} |
|
83
|
2
|
|
|
|
|
146
|
return $str; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub as_file { |
|
87
|
1
|
|
|
1
|
1
|
735
|
my ( $self, $filename ) = @_; |
|
88
|
1
|
50
|
|
|
|
5
|
croak "No filename was set!" unless $filename; |
|
89
|
|
|
|
|
|
|
|
|
90
|
1
|
|
|
|
|
7
|
my $file = path($filename); |
|
91
|
1
|
|
|
|
|
56
|
$file->spew( { binmode => ":encoding(UTF-8)" }, $self->as_string() ); |
|
92
|
1
|
|
|
|
|
2193
|
return $file; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
__END__ |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=encoding UTF8 |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 NAME |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Text::vCard::Precisely::Multiple - some add-on for Text::vCard::Precisely |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my $vcm = Text::vCard::Precisely::Multiple->new(); # default is 3.0 |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
my $path = path( 'some', 'dir', 'example.vcf' ); |
|
110
|
|
|
|
|
|
|
$vcm->load_file($path); |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
or |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
my $arrayref = [ |
|
115
|
|
|
|
|
|
|
{ |
|
116
|
|
|
|
|
|
|
N => [ 'Gump', 'Forrest', '', 'Mr.', '' ], |
|
117
|
|
|
|
|
|
|
FN => 'Forrest Gump', |
|
118
|
|
|
|
|
|
|
ORG => 'Bubba Gump Shrimp Co.', |
|
119
|
|
|
|
|
|
|
TITLE => 'Shrimp Man', |
|
120
|
|
|
|
|
|
|
TEL => [ |
|
121
|
|
|
|
|
|
|
{ types => ['WORK','VOICE'], content => '(111) 555-1212' }, |
|
122
|
|
|
|
|
|
|
], |
|
123
|
|
|
|
|
|
|
ADR =>[{ |
|
124
|
|
|
|
|
|
|
types => ['work'], |
|
125
|
|
|
|
|
|
|
pref => 1, |
|
126
|
|
|
|
|
|
|
extended => 100, |
|
127
|
|
|
|
|
|
|
street => 'Waters Edge', |
|
128
|
|
|
|
|
|
|
city => 'Baytown', |
|
129
|
|
|
|
|
|
|
region => 'LA', |
|
130
|
|
|
|
|
|
|
post_code => '30314', |
|
131
|
|
|
|
|
|
|
country => 'United States of America' |
|
132
|
|
|
|
|
|
|
}], |
|
133
|
|
|
|
|
|
|
EMAIL => 'forrestgump@example.com', |
|
134
|
|
|
|
|
|
|
REV => '20080424T195243Z', |
|
135
|
|
|
|
|
|
|
},{ |
|
136
|
|
|
|
|
|
|
N => [ 'One', 'Other', '', '', '' ], |
|
137
|
|
|
|
|
|
|
FN => 'Other One', |
|
138
|
|
|
|
|
|
|
TEL => [ |
|
139
|
|
|
|
|
|
|
{ types => ['HOME','VOICE'], content => '(404) 555-1212', preferred => 1 }, |
|
140
|
|
|
|
|
|
|
], |
|
141
|
|
|
|
|
|
|
ADR =>[{ |
|
142
|
|
|
|
|
|
|
types => ['home'], |
|
143
|
|
|
|
|
|
|
extended => 42, |
|
144
|
|
|
|
|
|
|
street => 'Plantation St.', |
|
145
|
|
|
|
|
|
|
city => 'Baytown', |
|
146
|
|
|
|
|
|
|
region => 'LA', |
|
147
|
|
|
|
|
|
|
post_code => '30314', |
|
148
|
|
|
|
|
|
|
country => 'United States of America' |
|
149
|
|
|
|
|
|
|
}], |
|
150
|
|
|
|
|
|
|
EMAIL => 'other.one@example.com', |
|
151
|
|
|
|
|
|
|
REV => '20080424T195243Z', |
|
152
|
|
|
|
|
|
|
}, |
|
153
|
|
|
|
|
|
|
]; |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
$vcm->load_arrayref($arrayref); |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
and |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
$vcm->as_string(); |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
or |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
$vcm->as_file('output.vcf'); |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=cut |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
If you have a file that contains multiple vCards, This module may be useful. |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 Constructors |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 load_arrayref($ArrayRef) |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Accepts an ArrayRef that looks like below: |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
my $arrayref = [ |
|
178
|
|
|
|
|
|
|
{ |
|
179
|
|
|
|
|
|
|
N => [ 'Gump', 'Forrest', '', 'Mr.', '' ], |
|
180
|
|
|
|
|
|
|
FN => 'Forrest Gump', |
|
181
|
|
|
|
|
|
|
ORG => 'Bubba Gump Shrimp Co.', |
|
182
|
|
|
|
|
|
|
TITLE => 'Shrimp Man', |
|
183
|
|
|
|
|
|
|
TEL => [ |
|
184
|
|
|
|
|
|
|
{ types => ['WORK','VOICE'], content => '(111) 555-1212' }, |
|
185
|
|
|
|
|
|
|
], |
|
186
|
|
|
|
|
|
|
ADR =>[{ |
|
187
|
|
|
|
|
|
|
types => ['work'], |
|
188
|
|
|
|
|
|
|
pref => 1, |
|
189
|
|
|
|
|
|
|
extended => 100, |
|
190
|
|
|
|
|
|
|
street => 'Waters Edge', |
|
191
|
|
|
|
|
|
|
city => 'Baytown', |
|
192
|
|
|
|
|
|
|
region => 'LA', |
|
193
|
|
|
|
|
|
|
post_code => '30314', |
|
194
|
|
|
|
|
|
|
country => 'United States of America' |
|
195
|
|
|
|
|
|
|
}], |
|
196
|
|
|
|
|
|
|
EMAIL => 'forrestgump@example.com', |
|
197
|
|
|
|
|
|
|
REV => '20080424T195243Z', |
|
198
|
|
|
|
|
|
|
},{...} |
|
199
|
|
|
|
|
|
|
]; |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head2 load_file($file_name) |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Accepts a file name |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head1 METHODS |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head2 as_string() |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Returns the vCards as a single string that is serialized. |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head2 as_file($filename) |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Write vCards formated text into a single file to $filename. |
|
214
|
|
|
|
|
|
|
Dies if not successful |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head1 SIMPLE GETTERS/SETTERS |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
These methods accept and return strings |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head2 version() |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
returns Version number of the vcard. |
|
223
|
|
|
|
|
|
|
Defaults to B<'3.0'> and this method is B<READONLY> |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head1 for under perl-5.12.5 |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
This module uses Text::vCard::Precisely and it require you to use 5.12.5 and later |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=over |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=item |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
L<RFC 2426|https://tools.ietf.org/html/rfc2426> |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=item |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
L<RFC 2425|https://tools.ietf.org/html/rfc2425> |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=item |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
L<RFC 6350|https://tools.ietf.org/html/rfc6350> |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=item |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
L<Text::vFile::asData> |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=back |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=head1 AUTHOR |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
Yuki Yoshida(L<worthmine|https://github.com/worthmine>) |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=head1 LICENSE |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under the same terms as Perl. |