Text-vCard-3.07000755000765000024 012456032363 12473 5ustar00leostaff000000000000README100644000765000024 55712456032363 13423 0ustar00leostaff000000000000Text-vCard-3.07 This archive contains the distribution Text-vCard, version 3.07: Edit and create vCards (RFC 2426) This software is copyright (c) 2015 by Leo Lapworth. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. This README file was generated by Dist::Zilla::Plugin::Readme v5.019. Changes100644000765000024 1612712456032363 14076 0ustar00leostaff000000000000Text-vCard-3.07Revision history for Perl extension Text::vCard. 3.07 Thu 15 Jan 2015 21:44:21 GMT - POD fixes (kablamo) 3.06 Thu 12 Jun 2014 19:55:51 BST - Fixed Text::vCard::Node->add_types() (kablamo) - Fix/guess for tests failing on windows (kablamo) 3.05 Tue 13 May 2014 18:04:30 BST - Another win attempt to fix (kablamo) - Get travis working! (kablamo) 3.04 Tue 29 Apr 2014 20:21:52 - Try a fix for Win32 (kablamo) 3.03 Fri 25 Apr 2014 19:23:43 - Better error msg for vcards w/o proper line endings (kablamo) - Bug fix for names. +test (kablamo) 3.02 Fri 14 Feb 18:35:55 2014 - Try fix Win32, switch File::Slurp to Path::Tiny (kablamo) 3.01 Mon 10 Feb 11:52:00 2014 - Try fix Win32 (kablamo) 3.0 Tue Jan 21 15:25:40 GMT 2014 - Major changes! - Initial release of vCard and vCard::AddressBook - Fix line unwrapping when reading vcards - Rewrote Text::vCard::Node->as_string() - Rewrote Text::vCard::AddressBook->export() - Redo the way that encoding and decoding works - Correctly wrap utf8 encoded strings - Fix encoding issues with MIME::Base64 and MIME::QuotedPrint - Do a better job escaping and unescaping '\', ';', and ',' - Fix for writing vcards with ORG values - Fix to remove extra semi colon when writing vcards - Version defaults to 4.0 when using the new vCard library 2.13 Thu 20 Dec 2012 19:34:44 GMT - Under the newer combined RFC6350 - every END:VCARD must be followed by \r\n (including last one)- reported by ysth - Fix for tests, should now work under Perl 5.17.6 - Ron Savage 2.12 Mon 10 Sep 2012 21:09:45 BST - perltidy everything - Adding base64 encode/decode (doriantaylor) 2.11 Thu 21 May 2012 08:48:46 BST - Merge POD cleanup and improvements (szabgab) 2.10 Tue 11 Jan 2011 21:50:02 GMT - Merged in quote-printed code (Christian Varga) - Cleaned up the tests and code for quote-printed 2.09 Thu 19 Aug 2010 16:08:20 BST - Add set_encoding() for export - Stefan 2.08 Tue Jul 13 08:47:58 BST 2010 - Doc fix (Blair Christensen) 2.07 Wed 28 Jan 2010 22:16:05 GMT - Fix bug in get_simple_type() (Philip A. Prindeville) - Simplify Makefile.PL and deprecate unused fields (Philip A. Prindeville) 2.06 Sun 24 Jan 2010 10:02:01 GMT - Doc typos (Philip A. Prindeville) - Add get_simple_type() and import_data() (Philip A. Prindeville) - Doc typos (Philip A. Prindeville) 2.05 Fri 8 Jan 2010 22:28:50 GMT - Put back changes which were missed out 2.04 Fri 8 Jan 2010 22:00:20 GMT - Improvements to Makefile.PL and require 5.6 - thanks cpanservice - Switch to git repo - Doc patch 2.03 Sun Mar 16 10:10:54 GMT 2008 - added 'moniker' and marked 'name' as depreciated 2.02 Sat Mar 15 17:15:16 GMT 2008 - http://rt.cpan.org/Ticket/Display.html?id=34044 Clean up tests so they pass in perl 5.10 thanks to Neil Williams 2.01 Sun Sep 2 2007 - Stop empty TYPE= being set on export when not needed thanks to Vadim for the suggestion 2.00 Sat Oct 21 2006 - export now gives 'TYPE=x,y' instead of the incorrect 'x;y' 1.99 Wed 30th Aug 2006 - Added 'quoted-printable' fix [rt.cpan.org #17790] this requires MIME::QuotedPrint 1.98 Mon Jul 17 2006 - Test fix 1.97 Sun Jul 2 2006 - removed test because I don't think Test::More::is_deaply works correctly on: perl 5.8.0 on Solaris x86 9 1.96 Sun 3rd July 2005 - Removed String::ShellQuote - forgot to PREREQ and not using it 1.95 Sun 26th June 2005 - Made export() work for address book, still missing encoding though. - Added basic test for export() - A few little clean up things 1.94 Sun 24th April 2005 - Made check for 'VCARD' tag case insensative, probably won't help until Text::vFile::asData does as well. 1.93 Mon 31st Jan 2005 - Restructured object so all nodes are stored in a hashref $self->{nodes} so I can get get_group to work, all other methods updated to reflect this. - added get_group() to vcard 1.92 - Added group() to Node and extract that info from the vcard if it is there. 1.91 - Doc bug, said 'tels', should have been 'tel'. 1.9 - removed import() from docs as not used now - changed Node so excepts data with less than field order elements e.g. N, accepts 'Jon;Smith', As well as 'Jon;Smith;Dr;' this means we work better according to the RFC - ORGs' 'unit' method requires and returns an array ref as it is unlimited in the number of elements it has 1.8 Fri 15th Oct 2004 - Applied patch from Aaron Cope for version stuff, can now access it as lowercase version(). 1.7 Wed 13th Oct 2004 - remembered to update module versions as well as makefile! 1.6 Wed 13th Oct 2004 - removed import() and made anonsub again - removed version() as was conflicting with $VERSION, info can be accessed through other methods in anycase 1.5 Wed Oct 6th 2004 - Change to support asData change for 'type=home;type=pref' - Change to support escaped ; (\;) in data - 'note' now works 1.4 Tue Oct 5th 2004 - Patches from Arron for XML::Generator::vCard - put auto methods in sub rather than closure for vCard.pm - change read_file() to scalar read_file() in address 1.3 Tue Oct 5th 2004 - Added missing File::Slurp dependency - Renamed 'element_type' to 'node_type' as well - doc updates with help from binary 1.2 Sat Oct 2nd 2004 - Changed so can parse group.NODE, the group is ignored for now - Added test for apple vcard version 3 - emailed asData author about small buy with types (home/pref) - added autogen methods; $vcard->fn(), $vcard->fullname($value) 1.1 Wed Sept 15th 2003 - Lots of tests added - Restructured (it's Tom's fault) so we use Addressbook as the main interface, and Text::vCard is a single card, in the Addressbook object - Renamed add_type to add_types - Renamed remove_type to remove_types - Created Text::vCard::Node to replace all Text::vCard::Part* - Dropped requirement for Text::vFile - Created new and load methods, dropped iterator - Renamed update_value to export_data and changed returned value 1.0 Wed July 23rd 11:18:00 2003 - More doc fixing - Fixed bug in UID and TZ - test 02-evolution.t ready for Jay's 'type' fix to support v2.1 - test 03-phone_v1.t ready for Jay's 'type' fix to support v1.0 0.9 Sat July 07 10:19:00 2003 - Fixed major doc error! 0.8 Sat May 17 21:19:00 2003 - Added ability to specify types and tests - Altered add_type() and remove_type() to accept array ref as well 0.7 Tue May 13 08:00:00 2003 - Added emails, tels, lables. Started Binary API 0.6 Fri May 9 18:10:00 2003 - More accessor methods added, added the version to everything as well 0.5 Fri May 9 08:30:00 2003 - More accessor methods added, docs and tests 0.4 Wed May 7 14:48:20 2003 - Lots of new stuff, it's starting to take shape 0.3 Wed May 7 10:20:20 2003 - Cleaned up the docs, structure (now in lib/) and Makefile.PL 0.2 Tue May 6 12:30:20 2003 - Release for Jay to see 0.1 Mon May 5 11:50:20 2003 - original version LICENSE100644000765000024 4365312456032363 13614 0ustar00leostaff000000000000Text-vCard-3.07This software is copyright (c) 2015 by Leo Lapworth. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2015 by Leo Lapworth. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Suite 500, Boston, MA 02110-1335 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2015 by Leo Lapworth. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End INSTALL100644000765000024 165412456032363 13613 0ustar00leostaff000000000000Text-vCard-3.07 This is the Perl distribution Text-vCard. Installing Text-vCard is straightforward. ## Installation with cpanm If you have cpanm, you only need one line: % cpanm Text::vCard If you are installing into a system-wide directory, you may need to pass the "-S" flag to cpanm, which uses sudo to install the module: % cpanm -S Text::vCard ## Installing with the CPAN shell Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan Text::vCard ## Manual installation As a last resort, you can manually install it. Download the tarball, untar it, then build it: % perl Makefile.PL % make && make test Then install it: % make install If you are installing into a system-wide directory, you may need to run: % sudo make install ## Documentation Text-vCard documentation is available as POD. You can run perldoc from a shell to read the documentation: % perldoc Text::vCard META.yml100644000765000024 162312456032363 14027 0ustar00leostaff000000000000Text-vCard-3.07--- abstract: 'Edit and create vCards (RFC 2426)' author: - 'Leo Lapworth' - 'Eric Johnson (kablamo)' build_requires: Data::Dumper: '0' Directory::Scratch: '0' Test::More: '0' Test::Most: '0' lib: '0' configure_requires: ExtUtils::MakeMaker: '6.30' dynamic_config: 0 generated_by: 'Dist::Zilla version 5.019, CPAN::Meta::Converter version 2.133380' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Text-vCard requires: Carp: '0' Encode: '0' MIME::Base64: '3.07' MIME::QuotedPrint: '3.07' Moo: '0' Moo::Role: '0' Path::Tiny: '0' Text::Wrap: '0' Text::vFile::asData: '0.07' URI: '0' Unicode::LineBreak: '0' base: '0' perl: '5.006' strict: '0' vars: '0' warnings: '0' resources: bugtracker: https://github.com/ranguard/text-vcard/issues repository: https://github.com/ranguard/text-vcard version: '3.07' MANIFEST100644000765000024 145412456032363 13711 0ustar00leostaff000000000000Text-vCard-3.07# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.019. Changes INSTALL LICENSE MANIFEST MANIFEST.SKIP META.json META.yml Makefile.PL README lib/Text/vCard.pm lib/Text/vCard/Addressbook.pm lib/Text/vCard/Node.pm lib/vCard.pm lib/vCard/AddressBook.pm lib/vCard/Role/FileIO.pm t/01-node.t t/02-vcard.t t/03-addressbook.t t/04-formats.t t/05-export.t t/06-encoding.t t/06a-encoding2.t t/07-quoted.t t/08-base64.t t/apple_2.1_unicode.vcf t/apple_version3.vcf t/base64.vcf t/complete.vcf t/encoding.vcf t/encoding2.vcf t/escape.t t/evolution.vcf t/import-export.t t/latin1.vcf t/mix_type.vcf t/notes.vcf t/quoted.vcf t/quotedprintable.vcf t/release-no-tabs.t t/release-pod-syntax.t t/simple.vcf t/text/vcard/node/add_types.t t/types.t t/unwrap.t t/unwrap.vcf t/vcard.t t/vcard/address_book.t t000755000765000024 012456032363 12657 5ustar00leostaff000000000000Text-vCard-3.07types.t100644000765000024 52212456032363 14327 0ustar00leostaff000000000000Text-vCard-3.07/tuse Test::Most; use Text::vCard::Addressbook; my $address_book = Text::vCard::Addressbook->load( ['t/complete.vcf'] ); my $vcard = $address_book->vcards->[0]; my $phone_node = $vcard->get( { 'node_type' => 'phones' } )->[1]; my $types = $phone_node->types; is_deeply $types, [ 'cell', 'text' ], 'types()'; done_testing; vcard.t100644000765000024 1221112456032363 14320 0ustar00leostaff000000000000Text-vCard-3.07/tuse Test::Most; use Encode; use Path::Tiny qw/tempfile path/; use vCard; my $tmp_file = tempfile('.simple.vcfXXXX'); my $hashref = hashref(); my $vcard = vCard->new->load_hashref($hashref); subtest 'output methods' => sub { is $vcard->as_string, expected_vcard(), "as_string()"; is $vcard->as_file($tmp_file)->stringify, "$tmp_file", "as_file()"; my $tmp_contents = $tmp_file->slurp_utf8; is $tmp_contents, expected_vcard(), "file contents ok"; }; subtest 'simple getters' => sub { foreach my $node_type ( vCard->_simple_node_types ) { is $vcard->$node_type, $hashref->{$node_type}, $node_type; } }; subtest 'photo' => sub { $vcard->photo( $hashref->{photo} ); is ref( $vcard->photo ), 'URI::http', 'returns a URI::http object'; $vcard->photo( URI->new( $hashref->{photo} ) ); is ref( $vcard->photo ), 'URI::http', 'returns a URI::http object'; is $vcard->photo, $hashref->{photo}, 'photo'; }; subtest 'complex getters' => sub { is_deeply $vcard->family_names, ['Banner'], 'family_names()'; is_deeply $vcard->given_names, ['Bruce'], 'given_names()'; is_deeply $vcard->honorific_prefixes, ['Dr.'], 'prefixes'; is_deeply $vcard->honorific_suffixes, ['PhD'], 'suffixes'; my $phones = $vcard->phones; is_deeply $phones->[0]->{type}, ['work'], 'work phone'; is_deeply $phones->[1]->{type}, ['cell'], 'cell phone'; my $addresses = $vcard->addresses; is $addresses->[0]->{city}, 'Desert Base', 'work address'; is $addresses->[1]->{city}, 'Desert Base', 'home address'; my $emails = $vcard->email_addresses; is_deeply $emails->[0]->{type}, ['work'], 'work email address'; is_deeply $emails->[1]->{type}, ['home'], 'home email address'; }; subtest 'load_file() with chaining' => sub { my $vcard2 = vCard->new->load_file($tmp_file); test_simple_node_types($vcard2); }; subtest 'load_file() w/o chaining' => sub { my $vcard2 = vCard->new; $vcard2->load_file($tmp_file); test_simple_node_types($vcard2); }; subtest 'load_string() with chaining' => sub { my $tmp_contents = $tmp_file->slurp_utf8; my $vcard3 = vCard->new->load_string($tmp_contents); test_simple_node_types($vcard3); }; subtest 'load_string() w/o chaining' => sub { my $tmp_contents = $tmp_file->slurp_utf8; my $vcard3 = vCard->new; $vcard3->load_string($tmp_contents); test_simple_node_types($vcard3); }; # \r\n must be used as line endings. This is required by the RFC. subtest 'load_string() w/no carriage returns' => sub { my $string = raw_vcard(); $string =~ s/\r//g; throws_ok { vCard->new->load_string($string) } qr/ERROR/, 'caught exception for a string with no carriage returns'; }; done_testing; sub test_simple_node_types { my ($vcard) = @_; is ref $vcard, 'vCard', 'object type is good'; foreach my $node_type ( vCard->_simple_node_types ) { next if $node_type eq 'full_name'; is $vcard->$node_type, $hashref->{$node_type}, $node_type; } } # everything below this line is test data sub raw_vcard { return < 'Bruce Banner, PhD', given_names => ['Bruce'], family_names => ['Banner'], honorific_prefixes => ['Dr.'], honorific_suffixes => ['PhD'], title => 'Research Scientist', photo => 'http://shh.supersecret.army.mil/bbanner.gif', birthday => '19700414', timezone => 'UTC-7', phones => [ { type => ['work'], number => '651-290-1234', preferred => 1, }, { type => ['cell'], number => '651-290-1111' }, ], addresses => [ { type => ['work'], street => decode( 'utf8', '部队街' ), city => 'Desert Base', region => 'New Mexico', post_code => '55416', country => 'USA', }, { type => ['home'], street => 'Main St', city => 'Desert Base', region => 'New Mexico', post_code => '55416', country => 'USA', }, ], email_addresses => [ { type => ['work'], address => 'bbanner.work@example.com', preferred => 1 }, { type => ['home'], address => 'bbanner.home@example.com', }, ], }; } META.json100644000765000024 347612456032363 14207 0ustar00leostaff000000000000Text-vCard-3.07{ "abstract" : "Edit and create vCards (RFC 2426)", "author" : [ "Leo Lapworth", "Eric Johnson (kablamo)" ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 5.019, CPAN::Meta::Converter version 2.133380", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Text-vCard", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.30" } }, "develop" : { "requires" : { "Test::More" : "0", "Test::NoTabs" : "0", "Test::Pod" : "1.41" } }, "runtime" : { "requires" : { "Carp" : "0", "Encode" : "0", "MIME::Base64" : "3.07", "MIME::QuotedPrint" : "3.07", "Moo" : "0", "Moo::Role" : "0", "Path::Tiny" : "0", "Text::Wrap" : "0", "Text::vFile::asData" : "0.07", "URI" : "0", "Unicode::LineBreak" : "0", "base" : "0", "perl" : "5.006", "strict" : "0", "vars" : "0", "warnings" : "0" } }, "test" : { "requires" : { "Data::Dumper" : "0", "Directory::Scratch" : "0", "Test::More" : "0", "Test::Most" : "0", "lib" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/ranguard/text-vcard/issues" }, "repository" : { "type" : "git", "url" : "https://github.com/ranguard/text-vcard", "web" : "https://github.com/ranguard/text-vcard" } }, "version" : "3.07" } escape.t100644000765000024 45012456032363 14423 0ustar00leostaff000000000000Text-vCard-3.07/tuse Test::Most; use Text::vCard::Addressbook; use Path::Tiny; my $in_file = path('t/complete.vcf'); my $address_book = Text::vCard::Addressbook->load( [$in_file] ); my $vcard = $address_book->vcards->[0]; is $vcard->fullname, 'Bruce Banner, PhD', ', was not escaped'; done_testing; unwrap.t100644000765000024 140412456032363 14517 0ustar00leostaff000000000000Text-vCard-3.07/tuse Test::Most; use Directory::Scratch; use Path::Tiny; use vCard; # vCard files should have lines that are a max of 75 octets. When they are too # long the lines are wrapped. The first character on continued line must be a # space or a tab. This test makes sure that works. # see http://tools.ietf.org/search/rfc6350#section-3.2 my $in_file = path( 't', 'unwrap.vcf' ); note "Importing $in_file with Addressbook->load()"; my $address_book = Text::vCard::Addressbook->load( [$in_file] ); my $vcard = $address_book->vcards->[0]; my $expected_content = $in_file->slurp_utf8; my $actual_content = $vcard->as_string(); is $actual_content, $expected_content, 'vCard->as_string()'; is $address_book->export(), $actual_content, 'Addressbook->export()'; done_testing; 01-node.t100644000765000024 1421212456032363 14367 0ustar00leostaff000000000000Text-vCard-3.07/t#!/usr/bin/perl -w use strict; use lib qw(./lib); use Test::More tests => 41; use Data::Dumper; # Check we can load module BEGIN { use_ok('Text::vCard::Node'); } local $SIG{__WARN__} = sub { die $_[0] }; ##### # Set up some test data ##### # ok data my %data = ( 'params' => [ { 'type' => 'HOME,PREF', }, ], 'value' => ';;First work address - street;Work city;London;Work PostCode;CountryName', ); # Address fields my $fields = [ 'po_box', 'extended', 'street', 'city', 'region', 'post_code', 'country' ]; ##### # Test new() ##### my $foo = Text::vCard::Node::new( 'foo::bar', { fields => ['value'] } ); is( ref($foo), 'foo::bar', 'Can use as a base class' ); my $hash = Text::vCard::Node::new( { foo => 'bar' }, { 'fields' => ['value'] } ); is( ref($hash), 'HASH', 'new() retruns HASH when supplied hash' ); eval { Text::vCard::Node::new( undef, { 'fields' => ['value'] } ); }; like( $@, qr/Use of uninitialized value/, 'Errors if no class supplied' ); $@ = 'foo'; eval { Text::vCard::Node->new( {} ); }; like( $@, qr/No fields defined/, 'new() carps when no fields supplied' ); eval { Text::vCard::Node->new( { 'fields' => { 'duff' => 'hash' } } ); }; like( $@, qr/fields is not an array ref/, 'new() carps when fields is not an array ref' ); my %too_many_value_data = ( 'value' => 'asd;Street;Work city;London;Work PostCode;CountryName;more;values', ); eval { my $duff = Text::vCard::Node->new( { fields => $fields, data => \%too_many_value_data, } ); }; like( $@, qr/Data value had 8 elements expecting 7 or less/, 'new() carp on wrong number of elements in value comp to fields' ); my %a_few_data_points = ( 'value' => 'x;s;Street;City', ); # Working nodes my $nod_few_fields = Text::vCard::Node->new( { fields => $fields, data => \%a_few_data_points, } ); is( $nod_few_fields->street(), 'Street', 'new() - less data than fields, field set ok' ); is( $nod_few_fields->post_code(), undef, 'new() - less data, empty field returns undef' ); $nod_few_fields->post_code('postcode'); is( $nod_few_fields->post_code(), 'postcode', 'new() - less data, set empty field' ); # Create without a node_type - should be fine my $no = Text::vCard::Node->new( { fields => $fields, data => \%data, } ); # Create without a data - should be fine my $no_data = Text::vCard::Node->new( { fields => $fields, } ); is( $no_data->street(), undef, 'Created node with no data and methods created' ); # Create 'working' node my $node = Text::vCard::Node->new( { node_type => 'address', # Auto upper cased fields => $fields, data => \%data, group => 'item1', } ); is( $no->street(), $node->street(), 'new() without node_type still works ok' ); is( $node->group(), 'item1', 'got group as it was set' ); is( $node->group('FooF'), 'foof', 'set node worked' ); ### # ORG ### my %orgdata = ( 'value' => 'name;unit;extra', ); my $org = Text::vCard::Node->new( { node_type => 'ORG', fields => [ 'name', 'unit' ], data => \%orgdata, } ); is( scalar( @{ $org->unit() } ), 2, 'org - Got two elements back from unit' ); my @new_org = qw(a b c); is( scalar( @{ $org->unit( \@new_org ) } ), 3, 'org - Got the elements back from setting unit' ); is( scalar( @{ $org->unit('foo') } ), 3, 'org - Got the elements back from trying to set unit with string' ); my %single_org = ( 'value' => 'just_name', ); my $org_name = Text::vCard::Node->new( { node_type => 'ORG', fields => [ 'name', 'unit' ], data => \%single_org, } ); is( $org_name->unit(), undef, 'org - copes with unit being empty' ); ##### # types() ##### my $types = $node->types(); my @types = $node->types(); ok( scalar(@types), 'types() returns stuff' ); ok( eq_array( $types, \@types ), 'types() ok in array or scalar context' ); is( $no_data->types(), undef, 'types() get undef when there are none' ); ##### # is_type() ##### ok( $node->is_type('home'), 'is_type() home type matches' ); ok( !$node->is_type('work'), 'is_type() not work address type' ); is( $no_data->is_type('work'), undef, 'is_type() undef when no params' ); ##### # is_pref() ##### ok( $node->is_pref(), 'is_pref() this is a prefered address' ); $node->remove_types('pref'); is( $node->is_pref(), undef, 'is_pref() get undef when not pref' ); is( $no_data->is_pref(), undef, 'is_pref() get undef if no params' ); ##### # remove_types() ##### is( $no_data->remove_types('wibble'), undef, 'remove_types() when no params - no error' ); is( $node->remove_types('wibble'), undef, 'remove_types() undef when scalar, node has params and no match' ); is( $node->remove_types( ['home'] ), 1, 'remove_types() get a true value in array context when sucess' ); ##### # add_types() ##### # Test the types $node->add_types('WoRk'); ok( $node->is_type('wOrk'), 'is_type() Added work type and check non-cases sensative' ); $node->remove_types( [ 'Work', 'Home' ] ); ok( !$node->is_type('Work'), 'is_type() Removed work type and check non-cases sensative' ); ok( !$node->is_type('home'), 'is_type() Removed several types' ); $node->add_types( [ 'work', 'home' ] ); ok( $node->is_type('work') && $node->is_type('home'), 'is_type() Added two types ok' ); $no_data->add_types('work'); ok( $no_data->is_type('work'), 'is_type() Added type to node with no params' ); ##### # AUTOLOAD ##### is( $node->po_box(), '', 'AUTOLOAD - Po box empty as expected' ); is( $node->street(), 'First work address - street', 'AUTOLOAD - Street address matches' ); is( $node->country('Moose vill'), 'Moose vill', 'AUTOLOAD - set ok' ); eval { $node->duff_method(); }; like( $@, qr/duff_method method which is not valid for this node/, 'AUTOLOAD - carp when method not valid' ); #### # export_data() #### my $export = ';;First work address - street;Work city;London;Work PostCode;Moose vill'; is( $node->export_data(), $export, 'export_data() - Node returns expected data' ); delete $node->{'po_box'}; is( $node->export_data(), $export, 'export_data() - Node returns expected data, with undef entry' ); # Test non-existant methods notes.vcf100644000765000024 50212456032363 14624 0ustar00leostaff000000000000Text-vCard-3.07/tBEGIN:VCARD VERSION:3.0 N:;;;; FN:Test ORG:Test; TEL;type=WORK;type=pref:123/1234123 item1.ADR;type=WORK;type=pref:;;12a The Street.;Montreal;Quebec;;Canada item1.X-ABADR:ca NOTE:@prefix nasty \; with \; added into it and\n@prefix del: \n"\; ]]\;\n]\;\n. X-ABShowAs:COMPANY CATEGORY:montreal END:VCARD Makefile.PL100644000765000024 351112456032363 14526 0ustar00leostaff000000000000Text-vCard-3.07 # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.019. use strict; use warnings; use 5.006; use ExtUtils::MakeMaker 6.30; my %WriteMakefileArgs = ( "ABSTRACT" => "Edit and create vCards (RFC 2426)", "AUTHOR" => "Leo Lapworth, Eric Johnson (kablamo)", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.30" }, "DISTNAME" => "Text-vCard", "EXE_FILES" => [], "LICENSE" => "perl", "NAME" => "Text::vCard", "PREREQ_PM" => { "Carp" => 0, "Encode" => 0, "MIME::Base64" => "3.07", "MIME::QuotedPrint" => "3.07", "Moo" => 0, "Moo::Role" => 0, "Path::Tiny" => 0, "Text::Wrap" => 0, "Text::vFile::asData" => "0.07", "URI" => 0, "Unicode::LineBreak" => 0, "base" => 0, "strict" => 0, "vars" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "Data::Dumper" => 0, "Directory::Scratch" => 0, "Test::More" => 0, "Test::Most" => 0, "lib" => 0 }, "VERSION" => "3.07", "test" => { "TESTS" => "t/*.t t/text/vcard/node/*.t t/vcard/*.t" } ); my %FallbackPrereqs = ( "Carp" => 0, "Data::Dumper" => 0, "Directory::Scratch" => 0, "Encode" => 0, "MIME::Base64" => "3.07", "MIME::QuotedPrint" => "3.07", "Moo" => 0, "Moo::Role" => 0, "Path::Tiny" => 0, "Test::More" => 0, "Test::Most" => 0, "Text::Wrap" => 0, "Text::vFile::asData" => "0.07", "URI" => 0, "Unicode::LineBreak" => 0, "base" => 0, "lib" => 0, "strict" => 0, "vars" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); lib000755000765000024 012456032363 13162 5ustar00leostaff000000000000Text-vCard-3.07vCard.pm100644000765000024 2712612456032363 14747 0ustar00leostaff000000000000Text-vCard-3.07/libpackage vCard; $vCard::VERSION = '3.07'; use Moo; use Path::Tiny; use Text::vCard; use vCard::AddressBook; use URI; =head1 NAME vCard - Read, write, and edit vCards =head1 SYNOPSIS use vCard; # create the object my $vcard = vCard->new; # these methods load vCard data # (see method documentation for details) $vcard->load_file($filename); $vcard->load_string($string); $vcard->load_hashref($hashref); # simple getters/setters $vcard->full_name('Bruce Banner, PhD'); $vcard->title('Research Scientist'); $vcard->photo('http://example.com/bbanner.gif'); # complex getters/setters $vcard->phones([ { type => ['work', 'text'], number => '651-290-1234', preferred => 1 }, { type => ['home'], number => '651-290-1111' } ]); $vcard->email_addresses([ { type => ['work'], address => 'bbanner@ssh.secret.army.mil' }, { type => ['home'], address => 'bbanner@timewarner.com' }, ]); # these methods output data in vCard format my $file = $vcard->as_file($filename); # writes to $filename my $string = $vcard->as_string; # returns a string =head1 DESCRIPTION A vCard is a digital business card. vCard and L provide an API for parsing, editing, and creating vCards. This module is built on top of L. It provides a more intuitive user interface. To handle an address book with several vCard entries in it, start with L and then come back to this module. Note that the vCard RFC requires version() and full_name(). This module does not check or warn if these conditions have not been met. =head1 ENCODING AND UTF-8 See the 'ENCODING AND UTF-8' section of L. =head1 METHODS =cut has encoding_in => ( is => 'rw', default => sub {'UTF-8'} ); has encoding_out => ( is => 'rw', default => sub {'UTF-8'} ); has _data => ( is => 'rw', default => sub { { version => '4.0' } } ); with 'vCard::Role::FileIO'; =head2 load_hashref($hashref) $hashref should look like this: full_name => 'Bruce Banner, PhD', given_names => ['Bruce'], family_names => ['Banner'], title => 'Research Scientist', photo => 'http://example.com/bbanner.gif', phones => [ { type => ['work'], number => '651-290-1234', preferred => 1 }, { type => ['cell'], number => '651-290-1111' }, }, addresses => [ { type => ['work'], ... }, { type => ['home'], ... }, ], email_addresses => [ { type => ['work'], address => 'bbanner@shh.secret.army.mil' }, { type => ['home'], address => 'bbanner@timewarner.com' }, ], Returns $self in case you feel like chaining. =cut sub load_hashref { my ( $self, $hashref ) = @_; $self->_data($hashref); $self->_data->{version} = '4.0' unless $self->_data->{version}; $self->_data->{photo} = URI->new( $self->_data->{photo} ) unless ref $self->_data->{photo} =~ /^URI/; return $self; } =head2 load_file($filename) Returns $self in case you feel like chaining. =cut sub load_file { my ( $self, $filename ) = @_; my $addressBook = vCard::AddressBook->new({ encoding_in => $self->encoding_in, encoding_out => $self->encoding_out, }); my $vcard = $addressBook->load_file($filename)->vcards->[0]; $self->_data($vcard->_data); return $self; } =head2 load_string($string) Returns $self in case you feel like chaining. This method assumes $string is decoded (but not MIME decoded). =cut sub load_string { my ( $self, $string ) = @_; my $addressBook = vCard::AddressBook->new({ encoding_in => $self->encoding_in, encoding_out => $self->encoding_out, }); my $vcard = $addressBook->load_string($string)->vcards->[0]; $self->_data($vcard->_data); return $self; } =head2 as_string() Returns the vCard as a string. =cut sub as_string { my ($self) = @_; my $vcard = Text::vCard->new( { encoding_out => $self->encoding_out } ); my $phones = $self->_data->{phones}; my $addresses = $self->_data->{addresses}; my $email_addresses = $self->_data->{email_addresses}; $self->_build_simple_nodes( $vcard, $self->_data ); $self->_build_name_node( $vcard, $self->_data ); $self->_build_phone_nodes( $vcard, $phones ) if $phones; $self->_build_address_nodes( $vcard, $addresses ) if $addresses; $self->_build_email_address_nodes( $vcard, $email_addresses ) if $email_addresses; return $vcard->as_string; } sub _simple_node_types { qw/full_name title photo birthday timezone version/; } sub _build_simple_nodes { my ( $self, $vcard, $data ) = @_; foreach my $node_type ( $self->_simple_node_types ) { if ( $node_type eq 'full_name' ) { next unless $data->{full_name}; $vcard->fullname( $data->{full_name} ); } else { next unless $data->{$node_type}; $vcard->$node_type( $data->{$node_type} ); } } } sub _build_name_node { my ( $self, $vcard, $data ) = @_; my $value = join ',', @{ $data->{family_names} || [] }; $value .= ';' . join ',', @{ $data->{given_names} || [] }; $value .= ';' . join ',', @{ $data->{other_names} || [] }; $value .= ';' . join ',', @{ $data->{honorific_prefixes} || [] }; $value .= ';' . join ',', @{ $data->{honorific_suffixes} || [] }; $vcard->add_node( { node_type => 'N', data => [ { value => $value } ] } ) if $value ne ';;;;'; } sub _build_phone_nodes { my ( $self, $vcard, $phones ) = @_; foreach my $phone (@$phones) { # TODO: better error handling die "'number' attr missing from 'phones'" unless $phone->{number}; die "'type' attr in 'phones' should be an arrayref" if ( $phone->{type} && ref( $phone->{type} ) ne 'ARRAY' ); my $type = $phone->{type} || []; my $preferred = $phone->{preferred}; my $number = $phone->{number}; my $params = []; push @$params, { type => $_ } foreach @$type; push @$params, { pref => $preferred } if $preferred; $vcard->add_node( { node_type => 'TEL', data => [ { params => $params, value => $number } ], } ); } } sub _build_address_nodes { my ( $self, $vcard, $addresses ) = @_; foreach my $address (@$addresses) { die "'type' attr in 'addresses' should be an arrayref" if ( $address->{type} && ref( $address->{type} ) ne 'ARRAY' ); my $type = $address->{type} || []; my $preferred = $address->{preferred}; my $params = []; push @$params, { type => $_ } foreach @$type; push @$params, { pref => $preferred } if $preferred; my $value = join ';', $address->{pobox} || '', $address->{extended} || '', $address->{street} || '', $address->{city} || '', $address->{region} || '', $address->{post_code} || '', $address->{country} || ''; $vcard->add_node( { node_type => 'ADR', data => [ { params => $params, value => $value } ], } ); } } sub _build_email_address_nodes { my ( $self, $vcard, $email_addresses ) = @_; foreach my $email_address (@$email_addresses) { # TODO: better error handling die "'address' attr missing from 'email_addresses'" unless $email_address->{address}; die "'type' attr in 'email_addresses' should be an arrayref" if ( $email_address->{type} && ref( $email_address->{type} ) ne 'ARRAY' ); my $type = $email_address->{type} || []; my $preferred = $email_address->{preferred}; my $params = []; push @$params, { type => $_ } foreach @$type; push @$params, { pref => $preferred } if $preferred; # TODO: better error handling my $value = $email_address->{address}; $vcard->add_node( { node_type => 'EMAIL', data => [ { params => $params, value => $value } ], } ); } } =head2 as_file($filename) Write data in vCard format to $filename. Dies if not successful. =cut sub as_file { my ( $self, $filename ) = @_; my $file = $self->_path($filename); $file->spew( $self->_iomode_out, $self->as_string ); return $file; } =head1 SIMPLE GETTERS/SETTERS These methods accept and return strings. =head2 version() Version number of the vcard. Defaults to '4.0' =head2 full_name() A person's entire name as they would like to see it displayed. =head2 title() A person's position or job. =head2 photo() This should be a link. Accepts a string or a URI object. This method always returns a L object. TODO: handle binary images using the data uri schema =head2 birthday() =head2 timezone() =head1 COMPLEX GETTERS/SETTERS These methods accept and return array references rather than simple strings. =head2 family_names() Accepts/returns an arrayref of family names (aka surnames). =head2 given_names() Accepts/returns an arrayref. =head2 other_names() Accepts/returns an arrayref of names which don't qualify as family_names or given_names. =head2 honorific_prefixes() Accepts/returns an arrayref. eg C<[ 'Dr.' ]> =head2 honorific_suffixes() Accepts/returns an arrayref. eg C<[ 'Jr.', 'MD' ]> =head2 phones() Accepts/returns an arrayref that looks like: [ { type => ['work'], number => '651-290-1234', preferred => 1 }, { type => ['cell'], number => '651-290-1111' }, ] =head2 addresses() Accepts/returns an arrayref that looks like: [ { type => ['work'], street => 'Main St', preferred => 0 }, { type => ['home'], pobox => 1234, extended => 'asdf', street => 'Army St', city => 'Desert Base', region => '', post_code => '', country => 'USA', preferred => 1, }, ] =head2 email_addresses() Accepts/returns an arrayref that looks like: [ { type => ['work'], address => 'bbanner@ssh.secret.army.mil' }, { type => ['home'], address => 'bbanner@timewarner.com', preferred => 1 }, ] =cut sub version { shift->_setget( 'version', @_ ) } sub full_name { shift->_setget( 'full_name', @_ ) } sub family_names { shift->_setget( 'family_names', @_ ) } sub given_names { shift->_setget( 'given_names', @_ ) } sub other_names { shift->_setget( 'other_names', @_ ) } sub honorific_prefixes { shift->_setget( 'honorific_prefixes', @_ ) } sub honorific_suffixes { shift->_setget( 'honorific_suffixes', @_ ) } sub title { shift->_setget( 'title', @_ ) } sub photo { shift->_setget( 'photo', @_ ) } sub birthday { shift->_setget( 'birthday', @_ ) } sub timezone { shift->_setget( 'timezone', @_ ) } sub phones { shift->_setget( 'phones', @_ ) } sub addresses { shift->_setget( 'addresses', @_ ) } sub email_addresses { shift->_setget( 'email_addresses', @_ ) } sub _setget { my ( $self, $attr, $value ) = @_; $value = URI->new($value) if $value && $attr eq 'photo' && ref $value =~ /^URI/; $self->_data->{$attr} = $value if $value; return $self->_data->{$attr}; } =head1 AUTHOR Eric Johnson (kablamo), github ~!at!~ iijo dot org =head1 ACKNOWLEDGEMENTS Thanks to L for making this module possible by donating a significant amount of developer time. =cut 1; 02-vcard.t100644000765000024 1110312456032363 14536 0ustar00leostaff000000000000Text-vCard-3.07/t#!/usr/bin/perl -w use strict; use lib qw(./lib); use Test::More tests => 31; use Data::Dumper; # Check we can load module BEGIN { use_ok('Text::vCard'); } BEGIN { use_ok('Text::vCard::Addressbook'); } local $SIG{__WARN__} = sub { die $_[0] }; ####### # Test new() ####### my $function = Text::vCard::new( 'foo::bar', { 'source_file' => 't/simple.vcf' } ); is( ref($function), 'foo::bar', 'Can use as a base class' ); my $hash = Text::vCard::new( { foo => 'bar' }, { 'source_file' => 't/simple.vcf' } ); is( ref($hash), 'HASH', 'new() retruns HASH when supplied hash' ); eval { Text::vCard::new(undef); }; like( $@, qr/Use of uninitialized value/, 'Errors if no class supplied' ); $@ = 'foo'; my $adbk = Text::vCard::Addressbook->new( { 'source_file' => 't/simple.vcf' } ); my $vcard = $adbk->vcards()->[0]; ####### # Test add_node() ####### eval { $vcard->add_node(); }; like( $@, qr/Must supply a node_type/, 'Croak if add_node() not supplied with anything' ); eval { $vcard->add_node( {} ); }; like( $@, qr/Must supply a node_type/, 'Croak if add_node() not supplied with node_type' ); my %data = ( 'params' => [ { 'type' => 'HOME,PREF', }, ], 'value' => ';;First work address - street;Work city;London;Work PostCode;CountryName', ); my @d = ( \%data ); my $new_address = $vcard->add_node( { 'node_type' => 'ADR', 'data' => \@d, } ); isa_ok( $new_address, 'Text::vCard::Node' ); ###### # get_simple_type ###### is( $vcard->get_simple_type( 'tel', 'home' ), '020 666 6666' ); ####### # Test get_of_type() ####### my $home_adds_pref = $vcard->get_of_type( 'addresses', [ 'home', 'pref' ] ); is( scalar( @{$home_adds_pref} ), 2, 'get_of_type() types returns 2 not 3 addresses with array ref' ); is( $vcard->get_of_type('foo'), undef, 'nothing of this type found, undef returned' ); my $home_adds = $vcard->get_of_type( 'addresses', 'home' ); is( scalar( @{$home_adds} ), 3, 'get_of_type() types returns 3 not 3 addresses with scalar' ); is( $vcard->get_of_type( 'addresses', 'foo' ), undef, 'Undef returned when no addresses available' ); is( ref($home_adds), 'ARRAY', 'Returns array ref when called in context' ); my @list = $vcard->get_of_type( 'addresses', 'pref' ); is( scalar(@list), 2, 'Got all 2 addresses from array' ); my @list_all = $vcard->get_of_type('addresses'); is( scalar(@list_all), 3, 'Got 3 addresses from array as expected' ); ####### # Test get() ####### eval { $vcard->get(); }; like( $@, qr/You did not supply an element type/, 'get() croaks is no params supplied' ); my $addresses = $vcard->get( { 'node_type' => 'addresses' } ); my $also_addresses = $vcard->get('addresses'); ok( eq_array( $addresses, $also_addresses ), 'get() with single element and node_type match' ); my $home_adds_get = $vcard->get( { 'node_type' => 'addresses', 'types' => [ 'home', 'pref' ], } ); is( scalar( @{$home_adds_get} ), 2, 'get() types returns 2 not 3 addresses' ); ##### # test the auto generated methods ##### is( $vcard->FN(), 'T-firstname T-surname', 'autogen methods - got FN' ); is( $vcard->fullname('new name'), 'new name', 'autogen methods - updated fullname' ); is( $vcard->fn(), 'new name', 'autogen methods - got new fn' ); # try adding a new one is( $vcard->email(), undef, 'autogen methods - undef for no email as expected' ); is( $vcard->email('n.e@body.com'), 'n.e@body.com', 'autogen methods - new value set' ); is( $vcard->birthday('new bd'), 'new bd', 'autogen added with alias' ); ###### # ###### my $names = $vcard->get( { 'node_type' => 'name' } ); is( $names->[0]->family(), 'T-surname', 'got name - but this will be depreciated' ); my $names2 = $vcard->get( { 'node_type' => 'moniker' } ); is( $names2->[0]->family(), 'T-surname', 'got moniker' ); ###### # get get_group() ###### my $adgroup = Text::vCard::Addressbook->new( { 'source_file' => 't/apple_version3.vcf' } ); my $adgr_vcards = $adgroup->vcards(); my $adgr_vcard = $adgr_vcards->[0]; my $item1_nodes = $adgr_vcard->get_group('item1'); is( scalar( @{$item1_nodes} ), 2, 'get_group("item1") - got 2 nodes as arrayref - expected' ); my @item1_nodes_array = $adgr_vcard->get_group('item1'); is( scalar(@item1_nodes_array), 2, 'get_group("item1") - got 2 nodes as array - expected' ); my $item2_abadr = $adgr_vcard->get_group( 'item2', 'X-AbADR' ); is( $item2_abadr->[0]->value(), 'uk', 'get_group("item2","X-AbADR") - got value from node' ); eval { $adgr_vcard->get_group(); }; like( $@, qr/No group name supplied/, 'get_group - carp if no group name supplied' ); base64.vcf100644000765000024 412112456032363 14601 0ustar00leostaff000000000000Text-vCard-3.07/tBEGIN:VCARD VERSION:3.0 N:Victory;Photo;;; FN:Photo Victory ORG:For Great Justice™;; PHOTO;ENCODING=b;TYPE=x-evolution-unknown:R0lGODlhlgAyALMPAAAAAP9BAP////9PA P//AP/xAP/ZAP//Vv//sP+KAP+gAP9tAP9fAP+wAP/LAP///yH5BAEAAA8ALAAAAACWADIAQAT /8MlJq7046827/2DIAYIAVGRpAiyaqvApvXAtP2xc3hO9W6QWhcbD1VRF49GEARCe0JPzmZxSg VZC8pLVoqDenlPY3fbA2myxnGFvAIp4nCXfwuWKNd4MxOdRe4B/OH58Yn6DgnVthR0AA5CRkXa SA2uSVUI9lZeTKJAyj5iOoqBcnG2ojgGsrQF8AK6sPLGyLLNNta9YraG6u7eytlW2vL1mwbOGI szNzs/Q0SFBM0s2LjY3PkuaYtfYPx85TFg+duNITQjrCLTrVeztXPHtUvViLADx8Oy+9zP05GH ZB7AfEHqwEGpgYaBhQ4YPuTiMOGTish4TDayxiIIigIzL/z5mdFgFZBuTbxaoVAlg5QI7Ll+ic HlxRsw1NGfKxHHTQ8uV3WzmbNJzlbBdXIoNcUUrFrFjKJguxTWD6cVfSKP2WijVJ9ZXmr4O8yU sKBCqZ4+CFaM2q1a3PY7akRstX7l8ZvHlvRvSbq6aLq76XTh4GrUZ25A05RbK2jfEMc49HhEDh bUql9sUxhFkTWUu2dJV4wY6XYrFkYEo7vGZdbbSqZscmD3bV20gtA/Yyb13CADeuGtruz0jN/H gtKUA920c2e/lTQpIny5FulkA0wtUyQ4YO3cU34dYn5FdO+Hy3seLD88F/QgH8OGziG8nvnwU9 rvbd7AmP37+M+x31f9+/NXnXxMCjpDAgguywKAdDDaIQoTdRZjAGhROeOEMFtYEgIUbavggMh1 6yMCJDACAYopcrMjiECt25+IaMaJwYigz+lQjEDk20eMIlXhyyihDECmGJZ8YOYOSpYSiyhtPF qlkkkKOIBcyw0ylDGJwVbXVW1klo80veG2Gg1LSTKNWUPmUZVcyaCaFlpZgKSVWWWnN6WWcceH p1Za5ZMlFML35BouY5+hi5lK9IaoZVGlGKumklFbKmi/5HGEmOt2Uiddqg54mWaGgNTqOqaI2c xg6mQ1B2miOheONYpiB6oitkGmKxavTyMoZY5a1ymqrsOJarK+I1YpsYuS4yiv/CKcFi6xrxDJ bJrUrdCataM522tqxOygb264rdKsat75lE+1orGay2rrg2hEbEeCgm+63B/WjzTv58tuvv4viQ BAKAwsskMEFE6wvwgf3oJA6CSMnHA7JSbxbxSM05wLGxenWQ3PO8cYCdB0nhwzIC6HhhRVVgNF yFB6isYbLX4ThRhMyq1FzFG3I/EZ52rGgHnjUrcHez0fjkLR3obi3ENBFE01dG04vBJJIGknEU UUk+YQSRl1zHcrXuYykUUlbax32Qg203TYLbtvh9tsozN3d3A2sYXfdec+A91V45y333k38PUI hdyQyRCOLL+II4z0E0ngokC+ESCaV+5Y5/xcdZghEhyKGqKDnPZDOYYgfmq4Z6KGL/rnqudA0l E5A0b7TCEX1MLtQoeSeUu1A+G777W/EuKONx8+Q/EI/Ko8ijS+quHwb0+PQPPLP+xQkKJRMWQq Sn3RS5ZLjs2AKDlGmMiX541N5vpV0yflln3o6tQafZGpJ1vxcdQVmo1bxyZqagD//nek6BtyTW xRFPz3Jz4GcwQthJChAPz1wTljBy1ry1KX8KRBTbekgn5IVMBKSik6Q4iAG2wJACCqqTVC5Uwr pxKavnMOCb2AhPkKIlDsZglCDCuH+1oRAQKHQhfEzijLWAKdjMHGEvHCOm+43RQJu0AWCwmIAx VFCExiSioJpupZmupisN4DxLye0lBrXyEYPRAAAOw== REV:2012-09-06T01:57:22Z UID:pas-id-5048030200000000 END:VCARD latin1.vcf100644000765000024 65012456032363 14670 0ustar00leostaff000000000000Text-vCard-3.07/tBEGIN:VCARD FN:Bruce Banner\, PhD ADR;TYPE=home:;;Main St;Desert Base;New Mexico;55416;USA ADR;TYPE=work:;;Army St;Desert Base;New Mexico;55416;USA BDAY:19700414 EMAIL;PREF=1;TYPE=work:bbanner.work@example.com EMAIL;TYPE=home:bbanner.home@example.com PHOTO:http://shh.supersecret.army.mil/bbanner.gif TEL;PREF=1;TYPE=work:651-290-1234 TEL;TYPE=cell,text:651-290-1111 TITLE:Research Scientist TZ:UTC-7 END:VCARD quoted.vcf100644000765000024 31412456032363 14776 0ustar00leostaff000000000000Text-vCard-3.07/tBEGIN:VCARD VERSION:2.1 N:Smith;John;;; ADR;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:= ;;A street on a quoted line;Some test town;Some test region;0815;=C3=96= sterreich FN:John Smith END:VCARD simple.vcf100644000765000024 45712456032363 14776 0ustar00leostaff000000000000Text-vCard-3.07/tBEGIN:VCARD VERSION:2.1 N:T-surname;T-firstname;;; FN:T-firstname T-surname TEL;TYPE=HOME:020 666 6666 TEL;TYPE=CELL:0793 777 7777 ADR;TYPE=HOME:;;Test Road;Test City;;Test Postcode;Test Country ADR;TYPE=HOME,PREF:;;Pref Test Road;Pref Test City;;Pref Test Postcode;Pref Test Country END:VCARD unwrap.vcf100644000765000024 75212456032363 15017 0ustar00leostaff000000000000Text-vCard-3.07/tBEGIN:VCARD VERSION:2.1 N;CHARSET=utf-8;ENCODING=quoted-printable:mynameisveryveryveryveryveryvery= long FN:Bruce Banner\, PhD ADR;TYPE=home:;;Hover Valley Mountain Pass Road;Desert Base;New Mexico;5541 6;USA BDAY:19700414 EMAIL;PREF=1;TYPE=work:bbanner.work@example.com EMAIL;TYPE=home:bbanner.home@example.com PHOTO:http://shh.supersecret.army.mil/bbanner.gif TEL;PREF=1;TYPE=work:651-290-1234 TEL;TYPE=cell,text:651-290-1111 TITLE:Research Scientist TZ:UTC-7 END:VCARD MANIFEST.SKIP100644000765000024 1612456032363 14407 0ustar00leostaff000000000000Text-vCard-3.07dist.ini TODO 05-export.t100644000765000024 432712456032363 14755 0ustar00leostaff000000000000Text-vCard-3.07/t#!/usr/bin/perl -w use Test::Most; use lib qw(./lib); use Data::Dumper; # Check we can load module BEGIN { use_ok('Text::vCard::Addressbook'); } local $SIG{__WARN__} = sub { die $_[0] }; ####### # Test new() ####### my $adbk = Text::vCard::Addressbook->new( { 'source_file' => 't/apple_version3.vcf' } ); my $vcf = $adbk->export(); like( $vcf, qr/TYPE=work/, 'export() - added type def' ); my @lines = split( "\x0D\x0A", $vcf ); # \x0D\x0A == \r\n is( $lines[0], 'BEGIN:VCARD', 'export() - First line correct' ); is( $lines[$#lines], 'END:VCARD', 'export() - Last line correct' ); $adbk->set_encoding('utf-8'); my @data = ( 'BEGIN:VCARD', 'item1.X-ABADR:uk', 'item2.X-ABADR:uk', 'N:T-surname;T-first;;;', 'TEL;TYPE=home,pref:020 666 6666', 'TEL;TYPE=cell:0777 777 7777', 'item2.ADR;TYPE=work:;;Test Road;Test City;;Test Postcode;Test Country', 'item1.ADR;TYPE=home,pref:;;Pref Test Road;Pref Test City;;Pref Test Postcod', ' e;Pref Test Country', 'VERSION:3.0', 'FN:T-firstname T-surname', 'END:VCARD', ); @lines = split( "\x0D\x0A", $adbk->export() ); # \x0D\x0A == \r\n is_deeply( [ sort @lines ], [ sort @data ], 'set_encoding() - returned data matched that expected' ); #is_deeply(\@lines,\@data,'export() - returned data matched that expected'); #my $notes = Text::vCard::Addressbook->new({ 'source_file' => 't/notes.vcf'}); #print Dumper($notes); #my $res = $notes->export(); #print Dumper($res); { my $ab = Text::vCard::Addressbook->new(); is $ab->export, '', 'export empty addressbook'; my $vcard = $ab->add_vcard; isa_ok $vcard, 'Text::vCard'; like $ab->export, qr{^BEGIN:VCARD\s+END:VCARD\x0D\x0A$}, 'single empty vcard'; $vcard->fullname('Foo Bar'); $vcard->EMAIL('foo@bar.com'); my $node = $vcard->add_node( { 'node_type' => 'TEL', # fields => ['TYPE'], # data => { TYPE => 'Work' }, } ); isa_ok $node, 'Text::vCard::Node'; #$vcard->TEL('01-23456789'); eval { $vcard->random_field('Something else'); }; like $@, qr{Can't locate object method "random_field" via package "Text::vCard"}, 'exception'; #diag $ab->export; } done_testing; 07-quoted.t100644000765000024 106112456032363 14727 0ustar00leostaff000000000000Text-vCard-3.07/t#!/usr/bin/perl -w use strict; use lib qw(./lib); use Test::More tests => 3; BEGIN { use_ok('Text::vCard::Addressbook'); } my $address_book = Text::vCard::Addressbook->new( { 'source_file' => 't/quoted.vcf', } ); ok( $address_book, "Got an address book object" ); foreach my $vcard ( $address_book->vcards() ) { my $addresses = $vcard->get( { 'node_type' => 'ADR' } ); foreach my $address ( @{$addresses} ) { is( $address->street(), 'A street on a quoted line', 'Got full (quoted address)' ); } } 08-base64.t100644000765000024 575412456032363 14530 0ustar00leostaff000000000000Text-vCard-3.07/t#!/usr/bin/perl use Test::More; use lib qw(./lib); use MIME::Base64; use Path::Tiny; BEGIN { use_ok('Text::vCard::Addressbook'); } my $address_book = Text::vCard::Addressbook # ->new( { 'source_file' => 't/base64.vcf', } ); ok( $address_book, "Got an address book object" ); my ($vcard) = ( $address_book->vcards ); ok( $vcard, 'vCard is present' ); my ($photo) = $vcard->get('photo'); ok( $photo, 'Photo is present' ); my $base64_image = 'R0lGODlhlgAyALMPAAAAAP9BAP////9PAP//AP/xAP/ZAP//Vv//sP+KAP+gAP9tAP9fAP+wAP/L AP///yH5BAEAAA8ALAAAAACWADIAQAT/8MlJq7046827/2DIAYIAVGRpAiyaqvApvXAtP2xc3hO9 W6QWhcbD1VRF49GEARCe0JPzmZxSgVZC8pLVoqDenlPY3fbA2myxnGFvAIp4nCXfwuWKNd4MxOdR e4B/OH58Yn6DgnVthR0AA5CRkXaSA2uSVUI9lZeTKJAyj5iOoqBcnG2ojgGsrQF8AK6sPLGyLLNN ta9YraG6u7eytlW2vL1mwbOGIszNzs/Q0SFBM0s2LjY3PkuaYtfYPx85TFg+duNITQjrCLTrVezt XPHtUvViLADx8Oy+9zP05GHZB7AfEHqwEGpgYaBhQ4YPuTiMOGTish4TDayxiIIigIzL/z5mdFgF ZBuTbxaoVAlg5QI7Ll+icHlxRsw1NGfKxHHTQ8uV3WzmbNJzlbBdXIoNcUUrFrFjKJguxTWD6cVf SKP2WijVJ9ZXmr4O8yUsKBCqZ4+CFaM2q1a3PY7akRstX7l8ZvHlvRvSbq6aLq76XTh4GrUZ25A0 5RbK2jfEMc49HhEDhbUql9sUxhFkTWUu2dJV4wY6XYrFkYEo7vGZdbbSqZscmD3bV20gtA/Yyb13 CADeuGtruz0jN/HgtKUA920c2e/lTQpIny5FulkA0wtUyQ4YO3cU34dYn5FdO+Hy3seLD88F/QgH 8OGziG8nvnwU9rvbd7AmP37+M+x31f9+/NXnXxMCjpDAgguywKAdDDaIQoTdRZjAGhROeOEMFtYE gIUbavggMh16yMCJDACAYopcrMjiECt25+IaMaJwYigz+lQjEDk20eMIlXhyyihDECmGJZ8YOYOS pYSiyhtPFqlkkkKOIBcyw0ylDGJwVbXVW1klo80veG2Gg1LSTKNWUPmUZVcyaCaFlpZgKSVWWWnN 6WWcceHp1Za5ZMlFML35BouY5+hi5lK9IaoZVGlGKumklFbKmi/5HGEmOt2Uiddqg54mWaGgNTqO qaI2cxg6mQ1B2miOheONYpiB6oitkGmKxavTyMoZY5a1ymqrsOJarK+I1YpsYuS4yiv/CKcFi6xr xDJbJrUrdCataM522tqxOygb264rdKsat75lE+1orGay2rrg2hEbEeCgm+63B/WjzTv58tuvv4vi QBAKAwsskMEFE6wvwgf3oJA6CSMnHA7JSbxbxSM05wLGxenWQ3PO8cYCdB0nhwzIC6HhhRVVgNFy FB6isYbLX4ThRhMyq1FzFG3I/EZ52rGgHnjUrcHez0fjkLR3obi3ENBFE01dG04vBJJIGknEUUUk +YQSRl1zHcrXuYykUUlbax32Qg203TYLbtvh9tsozN3d3A2sYXfdec+A91V45y333k38PUIhdyQy RCOLL+II4z0E0ngokC+ESCaV+5Y5/xcdZghEhyKGqKDnPZDOYYgfmq4Z6KGL/rnqudA0lE5A0b7T CEX1MLtQoeSeUu1A+G777W/EuKONx8+Q/EI/Ko8ijS+quHwb0+PQPPLP+xQkKJRMWQqSn3RS5ZLj s2AKDlGmMiX541N5vpV0yflln3o6tQafZGpJ1vxcdQVmo1bxyZqagD//nek6BtyTWxRFPz3Jz4Gc wQthJChAPz1wTljBy1ry1KX8KRBTbekgn5IVMBKSik6Q4iAG2wJACCqqTVC5UwrpxKavnMOCb2Ah PkKIlDsZglCDCuH+1oRAQKHQhfEzijLWAKdjMHGEvHCOm+43RQJu0AWCwmIAxVFCExiSioJpupZm upisN4DxLye0lBrXyEYPRAAAOw==' . "\x0A"; my $base64_image_decoded = MIME::Base64::decode($base64_image); is $photo->value, $base64_image_decoded, 'compare decoded values'; my $photo_value = MIME::Base64::encode( $photo->value ); is $photo_value, $base64_image, 'compare encoded values'; # $vcard->as_string returns a decoded string. # slurp_utf8() returns a decoded string my $original_vcard = path('t/base64.vcf')->slurp_utf8; is $vcard->as_string, $original_vcard, 'as_string() output is the same as the input'; # Uncomment these lines to view the gif and inspect the new and original images # visually. #path('/tmp/victoly_original.gif')->spew($base64_image_decoded); #path('/tmp/victoly_new.gif')->spew( $photo->value ); done_testing; 04-formats.t100644000765000024 227612456032363 15107 0ustar00leostaff000000000000Text-vCard-3.07/t#!/usr/bin/perl -w use strict; use lib qw(./lib); use Test::More tests => 17; # Check we can load module use Data::Dumper; BEGIN { use_ok('Text::vCard::Addressbook'); } my @card_types = qw(evolution.vcf apple_2.1_unicode.vcf apple_version3.vcf); foreach my $card_type (@card_types) { ok( $card_type, "Running from $card_type" ); my $adbk = Text::vCard::Addressbook->new( { source_file => "t/$card_type" } ); isa_ok( $adbk, 'Text::vCard::Addressbook' ); my $vcards = $adbk->vcards(); is( scalar( @{$vcards} ), 1, "$card_type has 1 vcards as expected" ); my $vcard = $vcards->[0]; is( $vcard->get('fn')->[0]->value(), 'T-firstname T-surname', "$card_type has fn data correct" ); # print Dumper($vcard); my $t = $vcard->get( { 'node_type' => 'tel', 'types' => 'home', } ); is( $t->[0]->value(), '020 666 6666', 'got expected phone number' ); } my $adbk = Text::vCard::Addressbook->new( { source_file => "t/notes.vcf" } ); my $vcards = $adbk->vcards(); my $note = $vcards->[0]->note; is( $note, '@prefix nasty ; with ; added into it and\n@prefix del: \n"; ]];\n];\n.', 'Got note ok' ); complete.vcf100644000765000024 72012456032363 15306 0ustar00leostaff000000000000Text-vCard-3.07/tBEGIN:VCARD VERSION:4.0 N:Banner;Bruce;;Dr.;PhD FN:Bruce Banner\, PhD ADR;TYPE=home:;;Main St;Desert Base;New Mexico;55416;USA ADR;TYPE=work:;;部队街;Desert Base;New Mexico;55416;USA BDAY:19700414 EMAIL;PREF=1;TYPE=work:bbanner.work@example.com EMAIL;TYPE=home:bbanner.home@example.com PHOTO:http://shh.supersecret.army.mil/bbanner.gif TEL;PREF=1;TYPE=work:651-290-1234 TEL;TYPE=cell,text:651-290-1111 TITLE:Research Scientist TZ:UTC-7 END:VCARD encoding.vcf100644000765000024 45112456032363 15265 0ustar00leostaff000000000000Text-vCard-3.07/tBEGIN:VCARD VERSION:2.1 N:Christiansen;Nathan;Paul;Mr.;I FN:Nathan Paul Christiansen I NICKNAME:The Professor TEL;WORK;FAX:(801) 234-1001 ADR;WORK;ENCODING=QUOTED-PRINTABLE:;Corporate;Software Development=0D=0A333 West River Park Drive;Provo;UT;8460= 4;United States of America END:VCARD mix_type.vcf100644000765000024 52012456032363 15332 0ustar00leostaff000000000000Text-vCard-3.07/tBEGIN:VCARD VERSION:2.1 N:T-surname;T-firstname;;; FN:T-firstname T-surname TEL;TYPE=HOME:020 666 6666 TEL;TYPE=CELL:0793 777 7777 ADR;TYPE=HOME:;;Test Road;Test City;;Test Postcode;Test Country ADR;TYPE=HOME,PREF:;;Pref Test Road;Pref Test City;;Pref Test Postcode;Pref Test Country END:VCARD BEGIN:FOO VERSION:2.1 END:FOO 06-encoding.t100644000765000024 154112456032363 15216 0ustar00leostaff000000000000Text-vCard-3.07/t#!/usr/bin/perl -w use strict; use lib qw(./lib); use Test::More tests => 7; # Check we can load module BEGIN { use_ok('Text::vCard::Addressbook'); } my $card_type = 'encoding.vcf'; ok( $card_type, "Running from $card_type" ); my $adbk = Text::vCard::Addressbook->new( { source_file => "t/$card_type" } ); isa_ok( $adbk, 'Text::vCard::Addressbook' ); my $vcards = $adbk->vcards(); is( scalar( @{$vcards} ), 1, "$card_type has 1 vcards as expected" ); my $vcard = $vcards->[0]; is( $vcard->get('fn')->[0]->value(), 'Nathan Paul Christiansen I', "$card_type has fn data correct" ); # print Dumper($vcard); my $a = $vcard->get( { 'node_type' => 'ADR', 'types' => 'work', } )->[0]; is( $a->street(), "Software Development\x0D\x0A333 West River Park Drive", 'Match on street' ); is( $a->city(), 'Provo', 'Match on city' ); encoding2.vcf100644000765000024 62212456032363 15347 0ustar00leostaff000000000000Text-vCard-3.07/tBEGIN:VCARD VERSION:2.1 FN;ENCODING=QUOTED-PRINTABLE;CHARSET=utf-8:Bartholom=C3=A4us von St=C3=BCrm= er N;ENCODING=QUOTED-PRINTABLE;CHARSET=utf-8:von St=C3=BCrmer;Bartholom=C3=A4u= s;;; TEL;CELL:+08154711 END:VCARD BEGIN:VCARD VERSION:2.1 FN;ENCODING=QUOTED-PRINTABLE;CHARSET=utf-8:Carl Gau=C3=9F N;ENCODING=QUOTED-PRINTABLE;CHARSET=utf-8:Gau=C3=9F;Carl;;; TEL;VOICE:+471112345 END:VCARD evolution.vcf100644000765000024 23412456032363 15522 0ustar00leostaff000000000000Text-vCard-3.07/tBEGIN:VCARD VERSION:2.1 X-EVOLUTION-FILE-AS:Sister FN:T-firstname T-surname N:;Sister;;; TEL;HOME:020 666 6666 UID:pas-id-3EDER42342390 END:VCARD Text000755000765000024 012456032363 14106 5ustar00leostaff000000000000Text-vCard-3.07/libvCard.pm100644000765000024 3637512456032363 15701 0ustar00leostaff000000000000Text-vCard-3.07/lib/Textpackage Text::vCard; $Text::vCard::VERSION = '3.07'; use 5.006; use Carp; use strict; use warnings; use Text::vFile::asData 0.07; use Text::vCard::Node; # See this module for your basic parser functions use base qw(Text::vFile::asData); use vars qw (%lookup %node_aliases @simple); # If the node's data does not break down use this my @default_field = qw(value); # If it does use these %lookup = ( 'ADR' => [ 'po_box', 'extended', 'street', 'city', 'region', 'post_code', 'country' ], 'N' => [ 'family', 'given', 'middle', 'prefixes', 'suffixes' ], 'GEO' => [ 'lat', 'long' ], 'ORG' => [ 'name', 'unit' ], ); %node_aliases = ( 'FULLNAME' => 'FN', 'BIRTHDAY' => 'BDAY', 'TIMEZONE' => 'TZ', 'PHONES' => 'TEL', 'ADDRESSES' => 'ADR', 'NAME' => 'N', # To be deprecated as clashes with RFC 'MONIKER' => 'N', ); # Generate all our simple methods @simple = qw(FN BDAY MAILER TZ TITLE ROLE NOTE PRODID REV SORT-STRING UID URL CLASS FULLNAME BIRTHDAY TIMEZONE NAME EMAIL NICKNAME PHOTO); # Now we want lowercase as well map { push( @simple, lc($_) ) } @simple; # Generate the methods { no strict 'refs'; no warnings 'redefine'; # 'version' handled separately # to prevent conflict with ExtUtils::MakeMaker # and $VERSION for my $node ( @simple, "version" ) { *$node = sub { my ( $self, $value ) = @_; # See if we have it already my $nodes = $self->get($node); if ( !defined $nodes && $value ) { # Add it as a node if not exists and there is a value $self->add_node( { 'node_type' => $node, } ); # Get it out again $nodes = $self->get($node); } if ( scalar($nodes) && $value ) { # Set it $nodes->[0]->value($value); } return $nodes->[0]->value() if scalar($nodes); return undef; } } } =head1 NAME Text::vCard - Edit and create vCards (RFC 2426) =head1 WARNING L and L are built on top of this module and provide a more intuitive user interface. Please try those modules first. =head1 SYNOPSIS use Text::vCard; my $cards = Text::vCard->new( { 'asData_node' => $objects_node_from_asData, } ); =head1 DESCRIPTION A vCard is an electronic business card. This package is for a single vCard (person / record / set of address information). It provides an API to editing and creating vCards, or supplied a specific piece of the Text::vFile::asData results it generates a vCard with that content. You should really use L as this handles creating vCards from an existing file for you. =head1 METHODS =head2 new() use Text::vCard; my $new_vcard = Text::vCard->new(); my $existing_vcard = Text::vCard->new( { 'asData_node' => $objects_node_from_asData, } ); =cut sub new { my ( $proto, $conf ) = @_; my $class = ref($proto) || $proto; my $self = {}; bless( $self, $class ); $self->{encoding_out} = $conf->{encoding_out} || 'UTF-8'; my %nodes; $self->{nodes} = \%nodes; if ( defined $conf->{'asData_node'} ) { # Have a vcard data node being passed in while ( my ( $node_type, $data ) = each %{ $conf->{'asData_node'} } ) { my $group; if ( $node_type =~ /\./ ) { # Version 3.0 supports group types, we do not # so remove everything before '.' ( $group, $node_type ) = $node_type =~ /(.+)\.(.*)/; } # Deal with each type (ADR, FN, TEL etc) $self->_add_node( { 'node_type' => $node_type, 'data' => $data, 'group' => $group, } ); } } # else we're creating a new vCard return $self; } =head2 add_node() my $address = $vcard->add_node( { 'node_type' => 'ADR', } ); This creates a new address (a L object) in the vCard which you can then call the address methods on. See below for what options are available. The node_type parameter must conform to the vCard spec format (e.g. ADR not address) =cut sub add_node { my ( $self, $conf ) = @_; croak 'Must supply a node_type' unless defined $conf && defined $conf->{'node_type'}; unless ( defined $conf->{data} ) { my %empty; my @data = ( \%empty ); $conf->{'data'} = \@data; } $self->_add_node($conf); } =head2 get() The following method allows you to extract the contents from the vCard. # get all elements $nodes = $vcard->get('tel'); # Just get the home address my $nodes = $vcard->get( { 'node_type' => 'addresses', 'types' => 'home', } ); # get all phone number that matches serveral types my @types = qw(work home); my $nodes = $vcard->get( { 'node_type' => 'tel', 'types' => \@types, } ); Either an array or array ref is returned, containing L objects. If there are no results of 'node_type' undef is returned. Supplied with a scalar or an array ref the methods return a list of nodes of a type, where relevant. If any of the elements is the prefered element it will be returned as the first element of the list. =cut sub get { my ( $self, $conf ) = @_; carp "You did not supply an element type" unless defined $conf; if ( ref($conf) eq 'HASH' ) { return $self->get_of_type( $conf->{'node_type'}, $conf->{'types'} ) if defined $conf->{'types'}; return $self->get_of_type( $conf->{'node_type'} ); } else { return $self->get_of_type($conf); } } =head2 get_simple_type() The following method is a convenience wrapper for accessing simple elements. $value = $vcard->get_simple_type( 'email', [ 'internet', 'work' ] ); If multiple elements match, then only the first is returned. If the object isn't found, or doesn't have a simple value, then undef is returned. The argument type may be ommitted, it can be a scalar, or it can be an array reference if multiple types are selected. =cut sub get_simple_type { my ( $self, $node_type, $types ) = @_; carp "You did not supply an element type" unless defined $node_type; my %hash = ( 'node_type', $node_type ); $hash{'types'} = $types if defined $types; my $node = $self->get( \%hash ); return undef unless $node && @{$node} > 0 && exists $node->[0]->{'value'}; $node->[0]->{'value'}; } =head2 nodes my $addresses = $vcard->get( { 'node_type' => 'address' } ); my $first_address = $addresses->[0]; # get the value print $first_address->street(); # set the value $first_address->street('Barney Rubble'); # See if it is part of a group if ( $first_address->group() ) { print 'Group: ' . $first_address->group(); } According to the RFC the following 'simple' nodes should only have one element, this is not enforced by this module, so for example you can have multiple URL's if you wish. =head2 simple nodes For simple nodes, you can also access the first node in the following way: my $fn = $vcard->fullname(); # or setting $vcard->fullname('new name'); The node will be automatically created if it does not exist and you supplied a value. undef is returned if the node does not exist. Simple nodes can be called as all upper or all lowercase method names. vCard Spec: 'simple' Alias -------------------- -------- FN fullname BDAY birthday MAILER TZ timezone TITLE ROLE NOTE PRODID REV SORT-STRING UID URL CLASS EMAIL NICKNAME PHOTO version (lowercase only) =head2 more complex vCard nodes vCard Spec Alias Methods on object ---------- ---------- ----------------- N name (depreciated as conflicts with rfc, use moniker) N moniker 'family','given','middle','prefixes','suffixes' ADR addresses 'po_box','extended','street','city','region','post_code','country' GEO 'lat','long' TEL phones LABELS ORG 'name','unit' (unit is a special case and will return an array reference) my $addresses = $vcard->get( { 'node_type' => 'addresses' } ); foreach my $address ( @{$addresses} ) { print $address->street(); } # Setting values on an address element $addresses->[0]->street('The burrows'); $addresses->[0]->region('Wimbeldon common'); # Checking an address is a specific type $addresses->[0]->is_type('fax'); $addresses->[0]->add_types('home'); $addresses->[0]->remove_types('work'); =head2 get_group() my $group_name = 'item1'; my $node_type = 'X-ABLABEL'; my $of_group = $vcard->get_group( $group_name, $node_type ); foreach my $label ( @{$of_group} ) { print $label->value(); } This method takes one or two arguments. The group name (accessable on any node object by using $node->group() - not all nodes will have a group, indeed most vcards do not seem to use it) and optionally the types of node you with to have returned. Either an array or array reference is returned depending on the calling context, if there are no matches it will be empty. =cut sub get_group { my ( $self, $group_name, $node_type ) = @_; my @to_return; carp "No group name supplied" unless defined $group_name and $group_name ne ''; $group_name = lc($group_name); if ( defined $node_type && $node_type ne '' ) { # After a specific node type my $nodes = $self->get($node_type); foreach my $node ( @{$nodes} ) { push( @to_return, $node ) if $node->group() eq $group_name; } } else { # We want everything from that group foreach my $node_loop ( keys %{ $self->{nodes} } ) { # Loop through each type my $nodes = $self->get($node_loop); foreach my $node ( @{$nodes} ) { if ( $node->group() ) { push( @to_return, $node ) if $node->group() eq $group_name; } } } } return wantarray ? @to_return : \@to_return; } =head1 BINARY METHODS These methods allow access to what are potentially binary values such as a photo or sound file. Binary values will be correctly encoded and decoded to/from base 64. API still to be finalised. =head2 photo() =head2 sound() =head2 key() =head2 logo() =cut sub DESTROY { } =head2 get_lookup This method is used internally to lookup those nodes which have multiple elements, e.g. GEO has lat and long, N (name) has family, given, middle etc. If you wish to extend this package (for custom attributes), overload this method in your code: sub my_lookup { return \%my_lookup; } *Text::vCard::get_lookup = \&my_lookup; This has not been tested yet. =cut sub get_lookup { my $self = shift; return \%lookup; } =head2 get_of_type() my $list = $vcard->get_of_type( $node_type, \@types ); It is probably easier just to use the get() method, which inturn calls this method. =cut # Used to get the right elements sub get_of_type { my ( $self, $node_type, $types ) = @_; # Upper case the name $node_type = uc($node_type); # See if there is an alias for it $node_type = uc( $node_aliases{$node_type} ) if defined $node_aliases{$node_type}; return undef unless defined $self->{nodes}->{$node_type}; if ($types) { # After specific types my @of_type; if ( ref($types) eq 'ARRAY' ) { @of_type = @{$types}; } else { push( @of_type, $types ); } my @to_return; foreach my $element ( @{ $self->{nodes}->{$node_type} } ) { my $check = 1; # assum ok for now foreach my $type (@of_type) { # set it as bad if we don't match $check = 0 unless $element->is_type($type); } if ( $check == 1 ) { push( @to_return, $element ); } } return undef unless scalar(@to_return); # Make prefered value first @to_return = sort { _sort_prefs($b) <=> _sort_prefs($a) } @to_return; return wantarray ? @to_return : \@to_return; } else { # Return them all return wantarray ? @{ $self->{nodes}->{$node_type} } : $self->{nodes}->{$node_type}; } } =head2 as_string Returns the vCard as a string. =cut sub as_string { my ( $self, $fields ) = @_; # derp my %e = map { lc $_ => 1 } @{ $fields || [] }; my @k = qw(VERSION N FN); if ($fields) { push @k, sort map { uc $_ } @$fields; } else { push @k, grep { $_ !~ /^(VERSION|N|FN)$/ } sort map { uc $_ } keys %{ $self->{nodes} }; } # 'perldoc perlport' says using \r\n is wrong and confusing for a few # reasons but mainly because the value of \n is different on different # operating systems. It recommends \x0D\x0A instead. my $newline = "\x0D\x0A"; my $begin = 'BEGIN:VCARD'; my $end = 'END:VCARD'; my @lines = ($begin); for my $k (@k) { my $nodes = $self->get($k); push @lines, map { $_->as_string() } @$nodes; } return join $newline, @lines, $end, ''; } sub _sort_prefs { my $check = shift; if ( $check->is_type('pref') ) { return 1; } else { return 0; } } # Private method for adding nodes sub _add_node { my ( $self, $conf ) = @_; my $value_fields = $self->get_lookup(); my $node_type = uc( $conf->{node_type} ); $node_type = $node_aliases{$node_type} if defined $node_aliases{$node_type}; my $field_list; if ( defined $value_fields->{$node_type} ) { # We know what the field list is $field_list = $value_fields->{$node_type}; } else { # No defined fields - use just the 'value' one $field_list = \@default_field; } unless ( defined $self->{nodes}->{$node_type} ) { # create space to hold list of node objects my @node_list_space; $self->{nodes}->{$node_type} = \@node_list_space; } my $last_node; foreach my $node_data ( @{ $conf->{data} } ) { my $node_obj = Text::vCard::Node->new( { node_type => $node_type, fields => $field_list, data => $node_data, group => $conf->{group} || '', encoding_out => $self->{encoding_out}, } ); push( @{ $self->{nodes}->{$node_type} }, $node_obj ); # store the last node so we can return it. $last_node = $node_obj; } return $last_node; } =head1 AUTHOR Leo Lapworth, LLAP@cuckoo.org Eric Johnson (kablamo), github ~!at!~ iijo dot org =head1 Repository (git) http://github.com/ranguard/text-vcard, git://github.com/ranguard/text-vcard.git =head1 COPYRIGHT Copyright (c) 2005-2010 Leo Lapworth. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L, L, L L, L L, =cut 1; 06a-encoding2.t100644000765000024 54512456032363 15424 0ustar00leostaff000000000000Text-vCard-3.07/tuse Test::Most; use lib 'lib'; use Text::vCard::Addressbook; my $card_type = 'encoding2.vcf'; my $address_book = Text::vCard::Addressbook # ->new( { source_file => "t/$card_type" } ); foreach my $vcard ( $address_book->vcards() ) { my $string = $vcard->as_string(); ok $string !~ /Gau=C3=83=C2=9F/, "no double encoding"; } done_testing; import-export.t100644000765000024 314112456032363 16034 0ustar00leostaff000000000000Text-vCard-3.07/tuse Test::Most; use Text::vCard::Addressbook; use Path::Tiny; # This test makes sure that the files we export are the same as what we # imported. This property is not true for every possible vcard, but it should # always be true for the vcards that are tested below. note "utf-8 encoded files"; foreach my $filename (qw|complete.vcf quotedprintable.vcf|) { note "Importing $filename with Addressbook->load()"; my $in_file = path( 't', $filename ); # load() uses ':encoding('UTF-8')' by default to slurp $in_file my $address_book = Text::vCard::Addressbook->load( [$in_file] ); my $vcard = $address_book->vcards->[0]; # This returns UTF-8 decoded content my $expected_content = $in_file->slurp_utf8; # This returns UTF-8 decoded content my $actual_content = $vcard->as_string(); # These are comparing 2 things that are both UTF-8 decoded is $actual_content, $expected_content, 'vCard->as_string()'; is $address_book->export(), $actual_content, 'Addressbook->export()'; } note "latin1 encoded files"; foreach my $filename (qw|latin1.vcf|) { note "Importing $filename with Addressbook->load()"; my $in_file = path( 't', $filename ); my $address_book = Text::vCard::Addressbook->load( [$in_file], { encoding_in => 'none', encoding_out => 'none' } ); my $vcard = $address_book->vcards->[0]; my $expected_content = $in_file->slurp_raw(); my $actual_content = $vcard->as_string(); is $actual_content, $expected_content, 'vCard->as_string()'; is $address_book->export(), $actual_content, 'Addressbook->export()'; } done_testing; 03-addressbook.t100644000765000024 402012456032363 15720 0ustar00leostaff000000000000Text-vCard-3.07/t#!/usr/bin/perl -w use strict; use Data::Dumper; use lib qw(./lib); use Test::More tests => 13; local $SIG{__WARN__} = sub { die $_[0] }; # Check we can load module BEGIN { use_ok('Text::vCard::Addressbook'); } ##### # load ##### my $load = Text::vCard::Addressbook->load( ['t/simple.vcf'] ); isa_ok( $load, 'Text::vCard::Addressbook' ); eval { Text::vCard::Addressbook->load( ['i/do/not/exist'] ); }; like( $@, qr/Unable to read file/, 'load() - croak when file does not exist' ); ###### # new() ###### # Can we create an empty address book my $newadbk = Text::vCard::Addressbook->new(); isa_ok( $newadbk, 'Text::vCard::Addressbook' ); eval { Text::vCard::Addressbook->new( { 'source_file' => 'i/do/not/exist' } ); }; like( $@, qr/Unable to read file/, 'new() - croak when unable to read file' ); eval { Text::vCard::Addressbook::new(undef); }; like( $@, qr/Use of uninitialized value/, 'new() - ok error when no proto supplied' ); my $foo = Text::vCard::Addressbook::new('foo::bar'); is( ref($foo), 'foo::bar', 'new() - Can use as a base class' ); my $hash = Text::vCard::Addressbook::new( { foo => 'bar' } ); is( ref($hash), 'HASH', 'new() - retruns HASH when supplied hash' ); eval { Text::vCard::Addressbook->new( { 'source_file' => 't/mix_type.vcf' } ); }; like( $@, qr/This file contains FOO/, 'new() - carp on non VCARD format' ); ##### # add_vcard() ##### # Create a new vCard my $vcard = $newadbk->add_vcard(); isa_ok( $vcard, 'Text::vCard' ); # Add a node to it my $address = $vcard->add_node( { 'node_type' => 'ADR', } ); # Add some data to the address. $address->street('19 The mews'); $address->city('Buffyvill'); ##### # vcards ##### # Now get it out of the address book my $card_a = $newadbk->vcards(); is( ref($card_a), 'ARRAY', 'vcards() - returns array ref when in context' ); is( $card_a->[0]->get( { 'node_type' => 'ADR' } )->[0]->street(), '19 The mews', 'exstracted address ok' ), my @vcard_list = $newadbk->vcards(); is( scalar(@vcard_list), 1, 'vcards() returns array when in context' ); release-no-tabs.t100644000765000024 102412456032363 16162 0ustar00leostaff000000000000Text-vCard-3.07/t BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::NoTabsTests 0.06 use Test::More 0.88; use Test::NoTabs; my @files = ( 'lib/Text/vCard.pm', 'lib/Text/vCard/Addressbook.pm', 'lib/Text/vCard/Node.pm', 'lib/vCard.pm', 'lib/vCard/AddressBook.pm', 'lib/vCard/Role/FileIO.pm' ); notabs_ok($_) foreach @files; done_testing; apple_version3.vcf100644000765000024 54512456032363 16434 0ustar00leostaff000000000000Text-vCard-3.07/tBEGIN:VCARD VERSION:3.0 N:T-surname;T-first;;; FN:T-firstname T-surname TEL;type=HOME;type=pref:020 666 6666 TEL;CELL:0777 777 7777 item1.ADR;type=HOME;type=pref:;;Pref Test Road;Pref Test City;;Pref Test Postcode;Pref Test Country item1.X-ABADR:uk item2.ADR;type=WORK:;;Test Road;Test City;;Test Postcode;Test Country item2.X-ABADR:uk END:VCARD quotedprintable.vcf100644000765000024 27012456032363 16700 0ustar00leostaff000000000000Text-vCard-3.07/tBEGIN:VCARD VERSION:2.1 N;CHARSET=utf-8;ENCODING=quoted-printable:Gau=C3=9F;Carl;;; FN;CHARSET=utf-8;ENCODING=quoted-printable:Carl Gau=C3=9F TEL;TYPE=voice:+471112345 END:VCARD vCard000755000765000024 012456032363 15145 5ustar00leostaff000000000000Text-vCard-3.07/lib/TextNode.pm100644000765000024 5231412456032363 16555 0ustar00leostaff000000000000Text-vCard-3.07/lib/Text/vCardpackage Text::vCard::Node; $Text::vCard::Node::VERSION = '3.07'; use strict; use warnings; use Carp; use Encode; use MIME::Base64 3.07; use MIME::QuotedPrint 3.07; use Unicode::LineBreak; use Text::Wrap; use vars qw ( $AUTOLOAD ); =head1 NAME Text::vCard::Node - Object for each node (line) of a vCard =head1 SYNOPSIS use Text::vCard::Node; my %data = ( 'param' => { 'HOME,PREF' => 'undef', }, 'value' => ';;First work address - street;Work city;London;Work PostCode;CountryName', ); my $node = Text::vCard::Node->new({ node_type => 'address', # Auto upper cased fields => ['po_box','extended','street','city','region','post_code','country'], data => \%data, }); =head1 DESCRIPTION Package used by Text::vCard so that each element: ADR, N, TEL etc are objects. You should not need to use this module directly, L does it all for you. =head1 METHODS =head2 new() my $node = Text::vCard::Node->new({ node_type => 'address', # Auto upper cased fields => \['po_box','extended','street','city','region','post_code','country'], data => \%data, }); =head2 value() # Get the value for a standard single value node my $value = $node->value(); # Or set the value $node->value('New value'); =head2 other()'s # The fields supplied in the conf area also methods. my $po_box = $node->po_box(); # if the node was an ADR. # Set the value. my $street = $node->street('73 Sesame Street'); =cut sub new { my ( $proto, $conf ) = @_; my $class = ref($proto) || $proto; my $self = {}; carp "No fields defined" unless defined $conf->{'fields'}; carp "fields is not an array ref" unless ref( $conf->{'fields'} ) eq 'ARRAY'; bless( $self, $class ); $self->{encoding_out} = $conf->{encoding_out} || 'UTF-8'; $self->{node_type} = uc( $conf->{node_type} ) if defined $conf->{node_type}; $self->group( $conf->{group} ) if defined $conf->{group}; # Store the field order. $self->{'field_order'} = $conf->{'fields'}; # store the actual field names so we can look them up my %fields; map { $fields{$_} = 1 } @{ $self->{'field_order'} }; $self->{'field_lookup'} = \%fields; if ( defined $conf->{'data'} ) { # Populate now, rather than later (via AUTOLOAD) # store values into object if ( defined $conf->{'data'}->{'params'} ) { my %params; # Loop through array foreach my $param_hash ( @{ $conf->{'data'}->{'params'} } ) { while ( my ( $key, $value ) = each %{$param_hash} ) { my $t = 'type'; # go through each key/value pair my $param_list = $key; if ( defined $value ) { $t = $key; # use value, not key as its 'type' => 'CELL', # not 'CELL' => undef $param_list = $value; } # These values might as well be useful for # something. Also get rid of any whitespace # pollution. for my $p ( split /\s*,\s*/, $param_list ) { $p =~ s/^\s*(.*?)\s*$/\L$1/; $p =~ s/\s+/ /g; $params{$p} = lc $t; } } } $self->{params} = \%params; } if ( defined $conf->{'data'}->{'value'} ) { # Store the actual data into the object if ( $self->is_type('q') or $self->is_type('quoted-printable') ) { my $value = $conf->{data}{value}; my $mime_decoded = MIME::QuotedPrint::decode($value); my $encode_decoded = Encode::decode( 'UTF-8', $mime_decoded ); my $unescaped = $self->_unescape($encode_decoded); $conf->{'data'}->{'value'} = $unescaped; } if ( $self->is_type('b') or $self->is_type('base64') ) { # Don't Encode::decode() $mime_decoded because it is usually # (99% of the time) a binary value like a photo and not a # string. # # Also do not escape binary values. my $value = $conf->{data}{value}; my $mime_decoded = MIME::Base64::decode($value); $conf->{data}{value} = $mime_decoded; # mimic what goes on below @{$self}{ @{ $self->{field_order} } } = ( $conf->{data}{value} ); } else { # the -1 on split is so ;; values create elements in # the array my @elements = split /(?{data}{value}, -1; if ( defined $self->{node_type} && $self->{node_type} eq 'ORG' ) { my @unescaped = $self->_unescape_list(@elements); $self->{'name'} = shift(@unescaped); $self->{'unit'} = \@unescaped if scalar(@unescaped) > 0; } # no need for explicit scalar elsif ( @elements <= @{ $self->{field_order} } ) { my @unescaped = $self->_unescape_list(@elements); # set the field values as the data # e.g. $self->{street} = 'The street' @{$self}{ @{ $self->{field_order} } } = @unescaped; } else { carp sprintf( 'Data value had %d elements expecting %d or less.', scalar @elements, scalar @{ $self->{field_order} } ); } } } } return $self; } sub _unescape { my ( $self, $value ) = @_; $value =~ s|\\([\\,;])|$1|g; return $value; } sub _unescape_list { my ( $self, @values ) = @_; return map { $self->_unescape($_) } @values; } =head2 node_type Returns the type of the node itself, e.g. ADR. =cut sub node_type { $_[0]->{node_type}; } =head2 unit() my @units = @{ $org_node->unit() }; $org_node->unit( [ 'Division', 'Department', 'Sub-department' ] ); As ORG allows unlimited numbers of 'units' as well as and organisation 'name', this method is a specific case for accessing those values, they are always returned as an array reference, and should always be set as an array reference. =cut sub unit { my ( $self, $val ) = @_; $self->{'unit'} = $val if $val && ref($val) eq 'ARRAY'; return $self->{'unit'} if defined $self->{'unit'}; return undef; } =head2 types() my @types = $node->types(); # or my $types = $node->types(); This method will return an array or an array ref depending on the calling context of types associated with the $node, undef is returned if there are no types. All types returned are lower case. =cut sub types { my $self = shift; my @types; return undef unless defined $self->{params}; foreach my $key ( sort keys %{ $self->{params} } ) { my $value = $self->{params}->{$key}; push @types, lc $key if $value && $value eq 'type'; } return wantarray ? @types : \@types; } =head2 is_type() if ( $node->is_type($type) ) { # ... } Given a type (see types() for a list of those set) this method returns 1 if the $node is of that type or undef if it is not. =cut sub is_type { my ( $self, $type ) = @_; if ( defined $self->{params} && exists $self->{params}->{ lc($type) } ) { # Make this always return true so as not to change the net # behaviour of the method. if for some wack (and # non-compliant) reason this value is undef, empty string or # zero, tough luck. return $self->{params}{ lc $type } || 1; } return undef; } =head2 is_pref(); if ( $node->is_pref() ) { print "Preferred node"; } This method is the same as is_type (which can take a value of 'pref') but it specific to if it is the preferred node. This method is used to sort when returning lists of nodes. =cut # A preferred node can be indicated in a vcard file 2 ways: # # 1. As 'PREF=1' which makes $self->{params} look like: # { 1 => 'pref', work => 'type' } # # 2. As 'TYPE=PREF' which makes $self->{params} look like: # { pref => 'type', work => 'type' } # sub is_pref { my $self = shift; my $params = $self->{params}; if (( defined $params ) && # ( defined $params->{1} && $params->{1} eq 'pref' ) || # ( defined $params->{pref} ) ) { return 1; } return undef; } =head2 add_types() $address->add_types('home'); my @types = qw(home work); $address->add_types( \@types ); Add a type to an address, it can take a scalar or an array ref. =cut sub add_types { my ( $self, $type ) = @_; unless ( defined $self->{params} ) { # no params, create a hash ref in there my %params; $self->{params} = \%params; } if ( ref($type) eq 'ARRAY' ) { map { $self->{params}->{ lc($_) } = 'type' } @{$type}; } else { $self->{params}->{ lc($type) } = 'type'; } } =head2 remove_types() $address->remove_types('home'); my @types = qw(home work); $address->remove_types( \@types ); This method removes a type from an address, it can take a scalar or an array ref. undef is returned when in scalar context and the type does not match, or when in array ref context and none of the types match, true is returned otherwise. =cut sub remove_types { my ( $self, $type ) = @_; return undef unless defined $self->{params}; if ( ref($type) eq 'ARRAY' ) { my $to_return = undef; foreach my $t ( @{$type} ) { if ( exists $self->{params}->{ lc($t) } ) { delete $self->{params}->{ lc($t) }; $to_return = 1; } } return $to_return; } else { if ( exists $self->{params}->{ lc($type) } ) { delete $self->{params}->{ lc($type) }; return 1; } } return undef; } =head2 group() my $group = $node->group(); If called without any arguments, this method returns the group name if a node belongs to a group. Otherwise undef is returned. If an argument is supplied then this is set as the group name. All group names are always lowercased. For example, Apple Address book used 'itemN' to group it's custom X-AB... nodes with a TEL or ADR node. =cut sub group { my $self = shift; if ( my $val = shift ) { $self->{group} = lc($val); } return $self->{group} if defined $self->{group}; return undef; } =head2 export_data() NOTE: This method is deprecated and should not be used. It will be removed in a later version. my $value = $node->export_data(); This method returns the value string of a node. It is only needs to be called when exporting the information back out to ensure that it has not been altered. =cut sub export_data { my $self = shift; my @lines = map { if ( defined $self->{$_} ) { if ( ref( $self->{$_} ) eq 'ARRAY' ) { # Handle things like org etc which have 'units' join( ',', @{ $self->{$_} } ); } else { $self->{$_}; } } else { ''; } } @{ $self->{'field_order'} }; # Should escape stuff here really, but waiting to see what # T::vfile::asData does return join( ';', @lines ); } =head2 as_string Returns the node as a formatted string. =cut sub _key_as_string { my ($self) = @_; my $n = ''; $n .= $self->group . '.' if $self->group; $n .= $self->node_type; $n .= $self->_params if $self->_params; return $n; } # returns a string of params formatted for saving to a vcard file # returns false if there are no params sub _params { my ($self) = @_; my %t; for my $t ( sort keys %{ $self->{params} } ) { my $backwards = uc $self->is_type( lc $t ); $t{$backwards} ||= []; push @{ $t{$backwards} }, lc $t; } $t{CHARSET} = [ lc $self->{encoding_out} ] if $self->{encoding_out} ne 'none' && $self->{encoding_out} !~ /UTF-8/i && !$self->is_type('b') && !$self->is_type('base64'); my @params = map { sprintf( '%s=%s', $_, join ',', @{ $t{$_} } ) } # sort keys %t; return @params ? ';' . join( ';', @params ) : undef; } # The vCard RFC requires commas, semicolons, and backslashes to be escaped. # See http://tools.ietf.org/search/rfc6350#section-3.4 # # Line breaks which are part of a value and are intended to be seen by humans # must have a value of '\n'. # See http://tools.ietf.org/search/rfc6350#section-4.1 # # Line breaks which happen because the RFC requires a line break after 75 # characters have a value of '\r\n'. These line breaks are not handled by # this method. See _newline() and # http://tools.ietf.org/search/rfc6350#section-3.2 # # Don't escape anything if this is a base64 node. Escaping only applies to # strings not binary values. # # 'perldoc perlport' says using \r\n is wrong and confusing for a few reasons # but mainly because the value of \n is different on different operating # systems. It recommends \x0D\x0A instead. sub _escape { my ( $self, $val ) = @_; return $val if ( $self->is_type('b') or $self->is_type('base64') ); $val =~ s/(\x0D\x0A|\x0D|\x0A)/\x0A/g; $val =~ s/([,;|])/\\$1/g; return $val; } sub _escape_list { my ( $self, @list ) = @_; return map { $self->_escape($_) } @list; } # The vCard RFC says new lines must be \r\n # See http://tools.ietf.org/search/rfc6350#section-3.2 # # 'perldoc perlport' says using \r\n is wrong and confusing for a few reasons # but mainly because the value of \n is different on different operating # systems. It recommends \x0D\x0A instead. sub _newline { my ($self) = @_; return "\x0D\x0A" if $self->{encoding_out} eq 'none'; return Encode::encode( $self->{encoding_out}, "\x0D\x0A" ); } sub _decode_string { my ( $self, $string ) = @_; return $string if $self->{encoding_out} eq 'none'; return Encode::decode( $self->{encoding_out}, $string ); } sub _encode_string { my ( $self, $string ) = @_; return $string if $self->{encoding_out} eq 'none'; return Encode::encode( $self->{encoding_out}, $string ); } sub _encode_list { my ( $self, @list ) = @_; return @list if $self->{encoding_out} eq 'none'; return map { $self->_encode_string($_) } @list; } # The vCard RFC says lines should be wrapped (or 'folded') at 75 octets # excluding the line break. The line is continued on the next line with a # space as the first character. See # http://tools.ietf.org/search/rfc6350#section-3.1 for details. # # Note than an octet is 1 byte (8 bits) and is not necessarily equal to 1 # character, 1 grapheme, 1 codepoint, or 1 column of output. Actually none of # those things are necessarily equal. See # http://www.perl.com/pub/2012/05/perlunicook-string-length-in-graphemes.html # # MIME::QuotedPrint does line wrapping but it assumes the line length must be # <= 76 chars which doesn't work for us. # # Can't use Unicode::LineBreak because it wraps by counting characters and the # vCard spec wants us to wrap by counting octets. sub _wrap { my ( $self, $key, $value ) = @_; return $self->_wrap_naively( $key, $value ) unless $self->{encoding_out} =~ /UTF-8/i; if ( $self->is_type('q') or $self->is_type('quoted-printable') ) { ## See the Quoted-Printable RFC205 ## https://tools.ietf.org/html/rfc2045#section-6.7 (rule 5) my $newline = $self->_encode_string("=") . $self->_newline . $self->_encode_string(" "); my $max = 73; # 75 octets per line max including '=' and ' ' from $newline return $self->_wrap_utf8( $key, $value, $max, $newline ); } my $newline = $self->_newline . $self->_encode_string(" "); my $max = 74; # 75 octets per line max including " " from $newline return $self->_wrap_utf8( $key, $value, $max, $newline ); } sub _wrap_utf8 { my ( $self, $key, $value, $max, $newline ) = @_; my $gcs = Unicode::GCString->new( $key . $value ); return $key . $value if $gcs->length <= $max; my $start = 0; my @wrapped_lines; # first line is 1 character longer than the others because it doesn't # begin with a " " my $first_max = $max + 1; while ( $start <= $gcs->length ) { my $len = 1; while ( ( $start + $len ) <= $gcs->length ) { my $line = $gcs->substr( $start, $len ); my $bytes = bytes::length( $line->as_string ); # is this a good place to line wrap? if ( $first_max && $bytes <= $first_max ) { ## no its not a good place to line wrap ## this if statement is only hit on the first line wrap $len++; next; } if ( $bytes <= $max ) { ## no its not a good place to line wrap $len++; next; } # wrap the line here $line = $gcs->substr( $start, $len - 1 )->as_string; push @wrapped_lines, $line; $start += $len - 1; last; } if ( ( $start + $len - 1 ) >= $gcs->length ) { my $line = $gcs->substr( $start, $len - 1 )->as_string; push @wrapped_lines, $line; last; } $first_max = undef; } return join $newline, @wrapped_lines; } # This will fail to line wrap properly for wide characters. The problem # is it naively wraps lines by counting the number of characters but the vcard # spec wants us to wrap after 75 octets (bytes). However clever vCard readers # may be able to deal with this. sub _wrap_naively { my ( $self, $key, $value ) = @_; $Text::Wrap::columns = 75; # wrap after 75 chars $Text::Wrap::break = qr/[.]/; # allow lines breaks anywhere $Text::Wrap::separator = $self->_newline; # use encoded new lines my $first_prefix = $key; # this text is placed before first line my $prefix = " "; # this text is placed before all other lines return Text::Wrap::wrap( $first_prefix, $prefix, $value ); } sub _encode { my ( $self, $value ) = @_; if ( $self->is_type('q') or $self->is_type('quoted-printable') ) { # Encode with Encode::encode() my $encoded_value = $self->_encode_string($value); return MIME::QuotedPrint::encode( $encoded_value, '' ); } elsif ( $self->is_type('b') or $self->is_type('base64') ) { # Scenarios where MIME::Base64::encode() works: # - for binary data (photo) -- 99% of cases # - if $value is a string with wide characters and the user has # encoded it as UTF-8. # - if $value is a string with no wide characters # # Scenario where MIME::Base64::encode() will die: # - if $value is a string with wide characters and the user has not # encoded it as UTF-8. return MIME::Base64::encode( $value, '' ); } else { $value = $self->_encode_string($value); } return $value; } # This method does the following: # 1. Escape and concatenate values # 2. Encode::encode() values # 3. MIME encode() values # 4. wrap lines to 75 octets # 5. Encode::decode() value # # Assumes there is only one MIME::Quoted-Printable field for a node. # Assumes there is only one MIME::Base64 field for a node. # # If either of the above assumptions is false, line wrapping may be incorrect. # However clever vCard readers may still be able to read vCards with incorrect # line wrapping. sub as_string { my ($self) = @_; my $key = $self->_key_as_string(); # Build up $raw_value from field values my @field_values; my $field_names = $self->{field_order}; foreach my $field_name (@$field_names) { next unless defined( my $field_value = $self->{$field_name} ); # escape stuff $field_value = ref $field_value eq 'ARRAY' # ? join( ';', $self->_escape_list(@$field_value) ) : $self->_escape($field_value); push @field_values, $field_value; } my $raw_value = join ';', @field_values; # MIME::*::encode() value my $encoded = $self->_encode($raw_value); # Line wrap everything to 75 octets my $wrapped = $self->_wrap( $key . ":", $encoded ); # Decode everything return $self->_decode_string($wrapped); } # Because we have autoload sub DESTROY { } # creates methods for a node object based on the field_names in the config # hash of the node. sub AUTOLOAD { my $name = $AUTOLOAD; $name =~ s/.*://; carp "$name method which is not valid for this node" unless defined $_[0]->{field_lookup}->{$name}; if ( $_[1] ) { # set it $_[0]->{$name} = $_[1]; } # Return it return $_[0]->{$name}; } =head2 NOTES If a node has a param of 'quoted-printable' then the value is escaped (basically converting Hex return into \r\n as far as I can see). =head1 AUTHOR Leo Lapworth, LLAP@cuckoo.org Eric Johnson (kablamo), github ~!at!~ iijo dot org =head1 SEE ALSO L L, L L, L L, =cut 1; vcard000755000765000024 012456032363 13756 5ustar00leostaff000000000000Text-vCard-3.07/taddress_book.t100644000765000024 660112456032363 16745 0ustar00leostaff000000000000Text-vCard-3.07/t/vcarduse Test::Most; use Path::Tiny qw/path tempfile/; use vCard::AddressBook; use Encode; my $in_file = path('t/complete.vcf'); my $out_file = tempfile('.vcard.out.vcfXXXX'); ##my $out_file = path('.vcard.out.vcf'); my $address_book = vCard::AddressBook->new; subtest 'load an address book' => sub { note 'add_vcard()'; $address_book->add_vcard; $address_book->add_vcard; $address_book->add_vcard; note 'load_file()'; $address_book->load_file($in_file); my $vcard = $address_book->vcards->[3]; note "simple getters and setters"; is $vcard->full_name, 'Bruce Banner, PhD', 'full_name()'; is $vcard->title, 'Research Scientist', 'title()'; is $vcard->photo, 'http://shh.supersecret.army.mil/bbanner.gif', 'photo()'; is ref $vcard->photo, 'URI::http', 'photo() returns a URI::http obj'; is $vcard->birthday, '19700414', 'birthday()'; is $vcard->timezone, 'UTC-7', 'timezone()'; note "complex getters and setters"; is_deeply $vcard->family_names, ['Banner'], 'family_names()'; is_deeply $vcard->given_names, ['Bruce'], 'given_names()'; is_deeply $vcard->other_names, [], 'other_names()'; is_deeply $vcard->honorific_prefixes, ['Dr.'], 'prefixes'; is_deeply $vcard->honorific_suffixes, ['PhD'], 'suffixes'; is_deeply $vcard->phones, expected_phones(), 'phones()'; is_deeply $vcard->addresses, expected_addresses(), 'addresses()'; is_deeply $vcard->email_addresses, expected_email_addresses(), 'email_addresses()'; }; subtest 'output address book' => sub { my $in_file_string = $in_file->slurp_utf8; $address_book->load_string($in_file_string); $address_book->as_file($out_file); my $contents = $out_file->slurp_utf8; is $contents, expected_out_file(), 'as_file()'; is scalar @{ $address_book->vcards }, 5, 'created the right # of vcards'; is ref $_, 'vCard', 'object reference' for @{ $address_book->vcards }; }; done_testing; sub expected_phones { [ { type => ['work'], number => '651-290-1234', preferred => 1 }, { type => [ 'cell', 'text' ], number => '651-290-1111', preferred => 0 } ]; } sub expected_addresses { [ { type => ['home'], preferred => 0, po_box => undef, street => 'Main St', city => 'Desert Base', region => 'New Mexico', post_code => '55416', country => 'USA', extended => undef, }, { type => ['work'], preferred => 0, po_box => undef, street => Encode::decode( 'UTF-8', '部队街' ), city => 'Desert Base', region => 'New Mexico', post_code => '55416', country => 'USA', extended => undef, }, ]; } sub expected_email_addresses { [ { type => ['work'], address => 'bbanner.work@example.com', preferred => 1 }, { type => ['home'], address => 'bbanner.home@example.com', preferred => 0 } ]; } sub expected_out_file { my $in_file_string = $in_file->slurp_utf8; return "BEGIN:VCARD\x0D\x0AVERSION:4.0\x0D\x0AEND:VCARD\x0D\x0A" x 3 . $in_file_string . $in_file_string; } release-pod-syntax.t100644000765000024 45612456032363 16715 0ustar00leostaff000000000000Text-vCard-3.07/t#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use Test::More; use Test::Pod 1.41; all_pod_files_ok(); apple_2.1_unicode.vcf100644000765000024 42412456032363 16666 0ustar00leostaff000000000000Text-vCard-3.07/tBEGIN:VCARD VERSION:2.1 N:T-surname;T-first;;; FN:T-firstname T-surname TEL;HOME:020 666 6666 TEL;CELL:0777 - 777 7777 ADR;HOME:;;Pref Test Road;Pref Test City;;Pref Test Postcode;Pref Test Country ADR;WORK:;;Test Road;Test City;;Test Postcode;Test Country END:VCARD vCard000755000765000024 012456032363 14221 5ustar00leostaff000000000000Text-vCard-3.07/libAddressBook.pm100644000765000024 2042112456032363 17136 0ustar00leostaff000000000000Text-vCard-3.07/lib/vCardpackage vCard::AddressBook; $vCard::AddressBook::VERSION = '3.07'; use Moo; use vCard; use Carp; use Text::vCard; use Text::vCard::Addressbook; =head1 NAME vCard::AddressBook - Read, write, and edit vCard address books =head1 SYNOPSIS use vCard::AddressBook; # create the object my $address_book = vCard::AddressBook->new(); # these methods load vCard formatted data $address_book->load_file('/path/file.vcf'); $address_book->load_string($string); my $vcard = $address_book->add_vcard; # returns a vCard object $vcard->full_name('Bruce Banner, PhD'); $vcard->family_names(['Banner']); $vcard->given_names(['Bruce']); $vcard->email_addresses([ { type => ['work'], address => 'bbanner@ssh.secret.army.mil' }, { type => ['home'], address => 'bbanner@timewarner.com' }, ]); # $address_book->vcards() returns an arrayref of vCard objects foreach my $vcard (@{ $address_book->vcards() }) { print $vcard->full_name() . "\n"; print $vcard->email_addresses->[0]->{address} . "\n"; } # these methods output data in vCard format my $file = $address_book->as_file('/path/file.vcf'); # write to a file my $string = $address_book->as_string(); =head1 DESCRIPTION A vCard is a digital business card. L and vCard::AddressBook provide an API for parsing, editing, and creating vCards. This module is built on top of L and L and provides a more intuitive user interface. =head1 ENCODING AND UTF-8 =head2 Constructor Arguments The 'encoding_in' and 'encoding_out' constructor parameters allow you to read and write vCard files with any encoding. Examples of valid values are 'UTF-8', 'Latin1', and 'none'. Both parameters default to 'UTF-8' and this should just work for the vast majority of people. The latest vCard RFC 6350 only allows UTF-8 as an encoding so most people should not need to use either parameter. =head2 MIME encodings vCard RFC 6350 only allows UTF-8 but it still permits 8bit MIME encoding schemes such as Quoted-Printable and Base64 which are supported by this module. =head2 Getting and setting values on a vCard object If you set values on a vCard object they must be decoded values. The only exception to this rule is if you are messing around with the 'encoding_out' constructor arg. When you get values from a vCard object they will be decoded values. =head1 METHODS =cut has encoding_in => ( is => 'rw', default => sub {'UTF-8'} ); has encoding_out => ( is => 'rw', default => sub {'UTF-8'} ); has vcards => ( is => 'rw', default => sub { [] } ); with 'vCard::Role::FileIO'; =head2 add_vcard() Creates a new vCard object and adds it to the address book. Returns a L object. =cut sub add_vcard { my ($self) = @_; my $vcard = vCard->new( { encoding_in => $self->encoding_in, encoding_out => $self->encoding_out, } ); push @{ $self->vcards }, $vcard; return $vcard; } =head2 load_file($filename) Load and parse the contents of $filename. Returns $self so the method can be chained. =cut sub load_file { my ( $self, $filename ) = @_; my $file = $self->_path($filename); my $string = $file->slurp( $self->_iomode_in ); $self->load_string($string); return $self; } =head2 load_string($string) Load and parse the contents of $string. This method assumes that $string is decoded (but not MIME decoded). Returns $self so the method can be chained. =cut sub load_string { my ( $self, $string ) = @_; die <_create_vcards($string); return $self; } sub _create_vcards { my ( $self, $string ) = @_; my $vcards_data = Text::vCard::Addressbook->new( { encoding_in => $self->encoding_in, encoding_out => $self->encoding_out, } )->_pre_process_text($string); foreach my $vcard_data (@$vcards_data) { carp "This file has $vcard_data->{type} data that was not parsed" unless $vcard_data->{type} =~ /VCARD/i; my $vcard = vCard->new( { encoding_in => $self->encoding_in, encoding_out => $self->encoding_out, } ); my $text_vcard = Text::vCard->new( { asData_node => $vcard_data->{properties}, encoding_out => $self->encoding_out, } ); $self->_copy_simple_nodes( $text_vcard => $vcard ); $self->_copy_name( $text_vcard => $vcard ); $self->_copy_photo( $text_vcard => $vcard ); $self->_copy_phones( $text_vcard => $vcard ); $self->_copy_addresses( $text_vcard => $vcard ); $self->_copy_email_addresses( $text_vcard => $vcard ); push @{ $self->vcards }, $vcard; } } sub _copy_simple_nodes { my ( $self, $text_vcard, $vcard ) = @_; foreach my $node_type ( vCard->_simple_node_types ) { if ( $node_type eq 'full_name' ) { next unless $text_vcard->fullname; $vcard->full_name( $text_vcard->fullname ); } else { next unless $text_vcard->$node_type; $vcard->$node_type( $text_vcard->$node_type ); } } } sub _copy_photo { my ( $self, $text_vcard, $vcard ) = @_; $vcard->photo( URI->new( $text_vcard->photo ) ); } sub _copy_name { my ( $self, $text_vcard, $vcard ) = @_; my ($node) = $text_vcard->get('n'); $vcard->family_names( [ $node->family || () ] ); $vcard->given_names( [ $node->given || () ] ); $vcard->other_names( [ $node->middle || () ] ); $vcard->honorific_prefixes( [ $node->prefixes || () ] ); $vcard->honorific_suffixes( [ $node->suffixes || () ] ); } sub _copy_phones { my ( $self, $text_vcard, $vcard ) = @_; my @phones; my $nodes = $text_vcard->get('tel') || []; foreach my $node (@$nodes) { my $phone; $phone->{type} = scalar $node->types; $phone->{preferred} = $node->is_pref ? 1 : 0; $phone->{number} = $node->value; push @phones, $phone; } $vcard->phones( \@phones ); } sub _copy_addresses { my ( $self, $text_vcard, $vcard ) = @_; my @addresses; my $nodes = $text_vcard->get('adr') || []; foreach my $node (@$nodes) { my $address; $address->{type} = scalar $node->types; $address->{preferred} = $node->is_pref ? 1 : 0; $address->{po_box} = $node->po_box || undef; $address->{street} = $node->street || undef; $address->{city} = $node->city || undef; $address->{post_code} = $node->post_code || undef; $address->{region} = $node->region || undef; $address->{country} = $node->country || undef; $address->{extended} = $node->extended || undef; push @addresses, $address; } $vcard->addresses( \@addresses ); } sub _copy_email_addresses { my ( $self, $text_vcard, $vcard ) = @_; my @email_addresses; my $nodes = $text_vcard->get('email') || []; foreach my $node (@$nodes) { my $email_address; $email_address->{type} = scalar $node->types; $email_address->{preferred} = $node->is_pref ? 1 : 0; $email_address->{address} = $node->value; push @email_addresses, $email_address; } $vcard->email_addresses( \@email_addresses ); } =head2 as_file($filename) Write all the vCards to $filename. Files are written as UTF-8 by default. Dies if not successful. =cut sub as_file { my ( $self, $filename ) = @_; my $file = $self->_path($filename); $file->spew( $self->_iomode_out, $self->as_string ); return $file; } =head2 as_string() Returns all the vCards as a single string. =cut sub as_string { my ($self) = @_; my $string = ''; $string .= $_->as_string for @{ $self->vcards }; return $string; } =head1 AUTHOR Eric Johnson (kablamo), github ~!at!~ iijo dot org =head1 ACKNOWLEDGEMENTS Thanks to L for making this module possible by donating a significant amount of developer time. =cut 1; Role000755000765000024 012456032363 15122 5ustar00leostaff000000000000Text-vCard-3.07/lib/vCardFileIO.pm100644000765000024 202212456032363 16723 0ustar00leostaff000000000000Text-vCard-3.07/lib/vCard/Rolepackage vCard::Role::FileIO; $vCard::Role::FileIO::VERSION = '3.07'; use Moo::Role; use Path::Tiny; requires qw/encoding_in encoding_out/; # PerlIO layers should look like ':encoding(UTF-8)' # The ':encoding()' part does character set and encoding transformations. # Without it you are just declaring the stream to be of a certain encoding. # See PerlIO, PerlIO::encoding docs. sub _iomode_out { my ($self) = @_; return { binmode => ':raw' } if $self->encoding_out eq 'none'; return { binmode => ':raw:encoding(' . $self->encoding_out . ')' }; } sub _iomode_in { my ($self) = @_; return { binmode => ':raw' } if $self->encoding_in eq 'none'; return { binmode => ':raw:encoding(' . $self->encoding_in . ')' }; } # Filename can be a string, a Path::Tiny obj, or a Path::Class obj. # Returns a Path::Tiny obj. sub _path { my ( $self, $filename ) = @_; return ref $filename eq 'Path::Class::File' # ? path("$filename") : path($filename); # works for strings and Path::Tiny objects } 1; Addressbook.pm100644000765000024 2372612456032363 20135 0ustar00leostaff000000000000Text-vCard-3.07/lib/Text/vCardpackage Text::vCard::Addressbook; $Text::vCard::Addressbook::VERSION = '3.07'; use Carp; use strict; use warnings; use Path::Tiny; use Text::vFile::asData; use Text::vCard; # See this module for your basic parser functions use base qw(Text::vFile::asData); =head1 NAME Text::vCard::Addressbook - Parse, edit, and create vCard address books (RFC 2426) =head1 WARNING L is built on top of this module and provides a more intuitive user interface. Please try that module first. =head1 SYNOPSIS use Text::vCard::Addressbook; # To read an existing address book file: my $address_book = Text::vCard::Addressbook->new({ 'source_file' => '/path/to/address_book.vcf', }); foreach my $vcard ( $address_book->vcards() ) { print "Got card for " . $vcard->fullname() . "\n"; } # To create a new address book file: my $address_book = Text::vCard::Addressbook->new(); my $vcard = $address_book->add_vcard; $vcard->fullname('Foo Bar'); $vcard->EMAIL('foo@bar.com'); open my $out, '>:encoding(UTF-8)', 'new_address_book.vcf' or die; print $out $address_book->export; =head1 DESCRIPTION This package provides an API to reading / editing and creating multiple vCards. A vCard is an electronic business card. This package has been developed based on rfc2426. You will find that many applications (Apple Address book, MS Outlook, Evolution etc) can export and import vCards. =head1 ENCODING AND UTF-8 =head2 Constructor Arguments The 'encoding_in' and 'encoding_out' constructor arguments allow you to read and write vCard files with any encoding. Examples of valid values are 'UTF-8', 'Latin1', and 'none'. Both values default to 'UTF-8' and this should just work for the vast majority of people. The latest vCard RFC 6350 only allows UTF-8 as an encoding so most people should not need to use either of these constructor arguments. =head2 MIME encodings vCard RFC 6350 only allows UTF-8 but it still permits 8bit MIME encoding schemes such as Quoted-Printable and Base64 which are supported by this module. =head2 Manually setting values on a Text::vCard or Text::vCard::Node object If you manually set values on a Text::vCard or Text::vCard::Node object they must be decoded values. The only exception to this rule is if you are messing around with the 'encoding_out' constructor arg. =head1 METHODS FOR LOADING VCARDS =head2 load() my $address_book = Text::vCard::Addressbook->load( [ 'foo.vCard', 'Addresses.vcf' ], # list of files to load ); This method will croak if it is unable to read in any of the files. =cut sub load { my ( $proto, $filenames, $constructor_args ) = @_; my $self = __PACKAGE__->new($constructor_args); foreach my $filename ( @{$filenames} ) { croak "Unable to read file $filename" unless -r $filename; my $file = $self->_path($filename); my $string = $file->slurp( $self->_iomode_in ); die <import_data($string); } return $self; } =head2 import_data() $address_book->import_data($string); This method imports data directly from a string. $string is assumed to be decoded (but not MIME decoded). =cut sub import_data { my ( $self, $value ) = @_; $self->_process_text($value); } =head2 new() # Create a new (empty) address book my $address_book = Text::vCard::Addressbook->new(); # Load vcards from a single file my $address_book = Text::vCard::Addressbook->new({ source_file => '/path/to/address_book.vcf' }); # Load vcards from a a string my $address_book = Text::vCard::Addressbook->new({ source_text => $source_text }); This method will croak if it is unable to read the source_file. The constructor accepts 'encoding_in' and 'encoding_out' attributes. The default values for both are 'UTF-8'. You can set them to 'none' if you don't want your output encoded with Encode::encode(). But be aware the latest vCard RFC 6350 mandates UTF-8. =cut sub new { my ( $proto, $conf ) = @_; my $class = ref($proto) || $proto; my $self = {}; bless( $self, $class ); # create some where to store out individual vCard objects $self->{'cards'} = []; $self->{encoding_in} = $conf->{encoding_in} || 'UTF-8'; $self->{encoding_out} = $conf->{encoding_out} || 'UTF-8'; # slurp in file contents if ( defined $conf->{'source_file'} ) { croak "Unable to read file $conf->{'source_file'}\n" unless -r $conf->{'source_file'}; my $filename = $conf->{source_file}; my $file = $self->_path($filename); $conf->{source_text} = $file->slurp( $self->_iomode_in ); } # Process the text if we have it. $self->_process_text( $conf->{'source_text'} ) if defined $conf->{'source_text'}; return $self; } =head1 OTHER METHODS =head2 add_vcard() my $vcard = $address_book->add_vcard(); This method creates a new empty L object, stores it in the address book and return it so you can add data to it. =cut sub add_vcard { my $self = shift; my $vcard = Text::vCard->new( { encoding_out => $self->{encoding_out} } ); push( @{ $self->{cards} }, $vcard ); return $vcard; } =head2 vcards() my $vcards = $address_book->vcards(); my @vcards = $address_book->vcards(); This method returns a reference to an array or an array of vcards in this address book. This could be an empty list if there are no entries in the address book. =cut sub vcards { my $self = shift; return wantarray ? @{ $self->{cards} } : $self->{cards}; } =head2 set_encoding() DEPRECATED. Use the 'encoding_in' and 'encoding_out' constructor arguments. =cut sub set_encoding { my ( $self, $coding ) = @_; $self->{'encoding'} |= ''; $self->{'encoding'} = ";charset=$coding" if ( defined $coding ); return $self->{'encoding'}; die "DEPRECATED. Use the 'encoding_in' and 'encoding_out'" . " constructor arguments"; } =head2 export() my $string = $address_book->export() This method returns the vcard data as a string in the vcf file format. Please note there is no validation, you must ensure that the correct nodes (FN,N,VERSION) are already added to each vcard if you want to comply with RFC 2426. =cut sub export { my $self = shift; my $string = ''; $string .= $_->as_string for $self->vcards; return $string; } # PRIVATE METHODS # PerlIO layers should look like ':encoding(UTF-8)' # The ':encoding()' part does character set and encoding transformations. # Without it you are just declaring the stream to be of a certain encoding. # See PerlIO, PerlIO::encoding docs. sub _iomode_in { my ($self) = @_; return { binmode => ':raw' } if $self->{encoding_in} eq 'none'; return { binmode => ':raw:encoding(' . $self->{encoding_in} . ')' }; } # Filename can be a string, a Path::Tiny obj, or a Path::Class obj. # Returns a Path::Tiny obj. sub _path { my ( $self, $filename ) = @_; return ref $filename eq 'Path::Class::File' # ? path("$filename") : path($filename); # works for strings and Path::Tiny objects } # Process a chunk of text, create Text::vCard objects and store in the address book sub _pre_process_text { my ( $self, $text ) = @_; if ( $text =~ /quoted-printable/i ) { # Edge case for 2.1 version # # http://tools.ietf.org/html/rfc2045#section-6.7 point (5), # lines containing quoted-printable encoded data can contain soft line # breaks. These are indicated as single '=' sign at the end of the # line. # # No longer needed in version 3.0: # http://tools.ietf.org/html/rfc2426 point (5) # # 'perldoc perlport' says using \r\n is wrong and confusing for a few # reasons but mainly because the value of \n is different on different # operating systems. It recommends \x0D\x0A instead. my $out; my $inside = 0; foreach my $line ( split( "\x0D\x0A", $text ) ) { if ($inside) { if ( $line =~ /=$/ ) { $line =~ s/=$//; } else { $inside = 0; } } if ( $line =~ /ENCODING=QUOTED-PRINTABLE/i ) { $inside = 1; $line =~ s/=$//; } $out .= $line . "\x0D\x0A"; } $text = $out; } # Add error checking here ? my $asData = Text::vFile::asData->new; $asData->preserve_params(1); my @lines = split "\x0D\x0A", $text; my @lines_with_newlines = map { $_ . "\x0D\x0A" } @lines; return $asData->parse_lines(@lines_with_newlines)->{objects}; } sub _process_text { my ( $self, $text ) = @_; my $cards = $self->_pre_process_text($text); foreach my $card (@$cards) { # Run through each card in the data if ( $card->{'type'} =~ /VCARD/i ) { my $vcard = Text::vCard->new( { 'asData_node' => $card->{'properties'}, encoding_in => $self->{encoding_in}, encoding_out => $self->{encoding_out} } ); push( @{ $self->{'cards'} }, $vcard ); } else { carp "This file contains $card->{'type'} data which was not parsed"; } } return $self->{cards}; } =head1 AUTHOR Leo Lapworth, LLAP@cuckoo.org Eric Johnson (kablamo), github ~!at!~ iijo dot org =head1 COPYRIGHT Copyright (c) 2003 Leo Lapworth. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 ACKNOWLEDGEMENTS The authors of L for making my life so much easier. =head1 SEE ALSO L, L =cut 1; node000755000765000024 012456032363 15667 5ustar00leostaff000000000000Text-vCard-3.07/t/text/vcardadd_types.t100644000765000024 66412456032363 20156 0ustar00leostaff000000000000Text-vCard-3.07/t/text/vcard/nodeuse Test::Most; use Text::vCard::Addressbook; my $address_book = Text::vCard::Addressbook->new; my $vcard = $address_book->add_vcard(); $vcard->version('2.07'); $vcard->fullname("My Name"); my $mail_node = $vcard->add_node({'node_type' => 'EMAIL'}); $mail_node->add_types('INTERNET'); $mail_node->value( "john\@example.org" ); my $string = $address_book->export; like $string, qr/TYPE=internet/, 'add_types() works'; done_testing;