Text-vCard-2.13000755000765000024 012064665273 12476 5ustar00leostaff000000000000README100644000765000024 47512064665273 13425 0ustar00leostaff000000000000Text-vCard-2.13 This archive contains the distribution Text-vCard, version 2.13: a package to edit and create a single vCard (RFC 2426) This software is copyright (c) 2012 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. Changes100644000765000024 1346412064665273 14102 0ustar00leostaff000000000000Text-vCard-2.13Revision history for Perl extension Text::vCard. 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 versionLICENSE100644000765000024 4365312064665273 13617 0ustar00leostaff000000000000Text-vCard-2.13This software is copyright (c) 2012 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) 2012 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) 2012 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 165412064665273 13616 0ustar00leostaff000000000000Text-vCard-2.13 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 136712064665273 14037 0ustar00leostaff000000000000Text-vCard-2.13--- abstract: 'a package to edit and create a single vCard (RFC 2426)' author: - 'Leo Lapworth' build_requires: Data::Dumper: 0 Digest: 0 Test::More: 0 configure_requires: ExtUtils::MakeMaker: 6.30 dynamic_config: 0 generated_by: 'Dist::Zilla version 4.300018, CPAN::Meta::Converter version 2.120921' 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 File::Slurp: 9999.04 MIME::Base64: 3.07 MIME::QuotedPrint: 3.07 Text::vFile::asData: 0.07 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: 2.13 MANIFEST100644000765000024 71212064665273 13670 0ustar00leostaff000000000000Text-vCard-2.13Changes 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 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/07-quoted.t t/08-base64.t t/apple_2.1_unicode.vcf t/apple_version3.vcf t/base64.vcf t/encoding.vcf t/evolution.vcf t/mix_type.vcf t/notes.vcf t/quoted.vcf t/release-no-tabs.t t/release-pod-syntax.t t/simple.vcf META.json100644000765000024 267412064665273 14211 0ustar00leostaff000000000000Text-vCard-2.13{ "abstract" : "a package to edit and create a single vCard (RFC 2426)", "author" : [ "Leo Lapworth" ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 4.300018, CPAN::Meta::Converter version 2.120921", "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" } }, "runtime" : { "requires" : { "Carp" : "0", "Encode" : "0", "File::Slurp" : "9999.04", "MIME::Base64" : "3.07", "MIME::QuotedPrint" : "3.07", "Text::vFile::asData" : "0.07", "base" : "0", "perl" : "5.006", "strict" : "0", "vars" : "0", "warnings" : "0" } }, "test" : { "requires" : { "Data::Dumper" : "0", "Digest" : "0", "Test::More" : "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" : "2.13" } t000755000765000024 012064665273 12662 5ustar00leostaff000000000000Text-vCard-2.1301-node.t100644000765000024 1421212064665273 14372 0ustar00leostaff000000000000Text-vCard-2.13/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 46512064665273 14637 0ustar00leostaff000000000000Text-vCard-2.13/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 240312064665273 14530 0ustar00leostaff000000000000Text-vCard-2.13 use strict; use warnings; use 5.006; use ExtUtils::MakeMaker 6.30; my %WriteMakefileArgs = ( "ABSTRACT" => "a package to edit and create a single vCard (RFC 2426)", "AUTHOR" => "Leo Lapworth", "BUILD_REQUIRES" => { "Data::Dumper" => 0, "Digest" => 0, "Test::More" => 0 }, "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.30" }, "DISTNAME" => "Text-vCard", "EXE_FILES" => [], "LICENSE" => "perl", "NAME" => "Text::vCard", "PREREQ_PM" => { "Carp" => 0, "Encode" => 0, "File::Slurp" => "9999.04", "MIME::Base64" => "3.07", "MIME::QuotedPrint" => "3.07", "Text::vFile::asData" => "0.07", "base" => 0, "strict" => 0, "vars" => 0, "warnings" => 0 }, "VERSION" => "2.13", "test" => { "TESTS" => "t/*.t" } ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) { my $br = delete $WriteMakefileArgs{BUILD_REQUIRES}; my $pp = $WriteMakefileArgs{PREREQ_PM}; for my $mod ( keys %$br ) { if ( exists $pp->{$mod} ) { $pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod}; } else { $pp->{$mod} = $br->{$mod}; } } } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); 02-vcard.t100644000765000024 1110312064665273 14541 0ustar00leostaff000000000000Text-vCard-2.13/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 412312064665273 14606 0ustar00leostaff000000000000Text-vCard-2.13/tBEGIN:VCARD VERSION:3.0 ORG:For Great Justiceā„¢;; FN:Photo Victory N:Victory;Photo;;; PHOTO;ENCODING=b;TYPE="X-EVOLUTION-UNKNOWN":R0lGODlhlgAyALMPAAAAAP9BAP////9 PAP//AP/xAP/ZAP//Vv//sP+KAP+gAP9tAP9fAP+wAP/LAP///yH5BAEAAA8ALAAAAACWADIAQ AT/8MlJq7046827/2DIAYIAVGRpAiyaqvApvXAtP2xc3hO9W6QWhcbD1VRF49GEARCe0JPzmZx SgVZC8pLVoqDenlPY3fbA2myxnGFvAIp4nCXfwuWKNd4MxOdRe4B/OH58Yn6DgnVthR0AA5CRk XaSA2uSVUI9lZeTKJAyj5iOoqBcnG2ojgGsrQF8AK6sPLGyLLNNta9YraG6u7eytlW2vL1mwbO GIszNzs/Q0SFBM0s2LjY3PkuaYtfYPx85TFg+duNITQjrCLTrVeztXPHtUvViLADx8Oy+9zP05 GHZB7AfEHqwEGpgYaBhQ4YPuTiMOGTish4TDayxiIIigIzL/z5mdFgFZBuTbxaoVAlg5QI7Ll+ icHlxRsw1NGfKxHHTQ8uV3WzmbNJzlbBdXIoNcUUrFrFjKJguxTWD6cVfSKP2WijVJ9ZXmr4O8 yUsKBCqZ4+CFaM2q1a3PY7akRstX7l8ZvHlvRvSbq6aLq76XTh4GrUZ25A05RbK2jfEMc49HhE DhbUql9sUxhFkTWUu2dJV4wY6XYrFkYEo7vGZdbbSqZscmD3bV20gtA/Yyb13CADeuGtruz0jN /HgtKUA920c2e/lTQpIny5FulkA0wtUyQ4YO3cU34dYn5FdO+Hy3seLD88F/QgH8OGziG8nvnw U9rvbd7AmP37+M+x31f9+/NXnXxMCjpDAgguywKAdDDaIQoTdRZjAGhROeOEMFtYEgIUbavggM h16yMCJDACAYopcrMjiECt25+IaMaJwYigz+lQjEDk20eMIlXhyyihDECmGJZ8YOYOSpYSiyht PFqlkkkKOIBcyw0ylDGJwVbXVW1klo80veG2Gg1LSTKNWUPmUZVcyaCaFlpZgKSVWWWnN6WWcc eHp1Za5ZMlFML35BouY5+hi5lK9IaoZVGlGKumklFbKmi/5HGEmOt2Uiddqg54mWaGgNTqOqaI 2cxg6mQ1B2miOheONYpiB6oitkGmKxavTyMoZY5a1ymqrsOJarK+I1YpsYuS4yiv/CKcFi6xrx DJbJrUrdCataM522tqxOygb264rdKsat75lE+1orGay2rrg2hEbEeCgm+63B/WjzTv58tuvv4v iQBAKAwsskMEFE6wvwgf3oJA6CSMnHA7JSbxbxSM05wLGxenWQ3PO8cYCdB0nhwzIC6HhhRVVg NFyFB6isYbLX4ThRhMyq1FzFG3I/EZ52rGgHnjUrcHez0fjkLR3obi3ENBFE01dG04vBJJIGkn EUUUk+YQSRl1zHcrXuYykUUlbax32Qg203TYLbtvh9tsozN3d3A2sYXfdec+A91V45y333k38P UIhdyQyRCOLL+II4z0E0ngokC+ESCaV+5Y5/xcdZghEhyKGqKDnPZDOYYgfmq4Z6KGL/rnqudA 0lE5A0b7TCEX1MLtQoeSeUu1A+G777W/EuKONx8+Q/EI/Ko8ijS+quHwb0+PQPPLP+xQkKJRMW QqSn3RS5ZLjs2AKDlGmMiX541N5vpV0yflln3o6tQafZGpJ1vxcdQVmo1bxyZqagD//nek6Bty TWxRFPz3Jz4GcwQthJChAPz1wTljBy1ry1KX8KRBTbekgn5IVMBKSik6Q4iAG2wJACCqqTVC5U wrpxKavnMOCb2AhPkKIlDsZglCDCuH+1oRAQKHQhfEzijLWAKdjMHGEvHCOm+43RQJu0AWCwmI AxVFCExiSioJpupZmupisN4DxLye0lBrXyEYPRAAAOw== UID:pas-id-5048030200000000 REV:2012-09-06T01:57:22Z END:VCARD quoted.vcf100644000765000024 30212064665273 14776 0ustar00leostaff000000000000Text-vCard-2.13/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 44512064665273 14776 0ustar00leostaff000000000000Text-vCard-2.13/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:VCARDMANIFEST.SKIP100644000765000024 1612064665273 14412 0ustar00leostaff000000000000Text-vCard-2.13dist.ini TODO 05-export.t100644000765000024 527312064665273 14761 0ustar00leostaff000000000000Text-vCard-2.13/t#!/usr/bin/perl -w use strict; use lib qw(./lib); use Test::More tests => 10; use Data::Dumper; # Check we can load module BEGIN { use_ok('Text::vCard::Addressbook'); } local $SIG{__WARN__} = sub { die $_[0] }; my @data = ( 'BEGIN:VCARD', 'item1.X-ABADR:uk', 'item2.X-ABADR:uk', 'N:T-surname;T-first;;;', 'TEL;pref;home:020 666 6666', 'TEL;cell:0777 777 7777', 'item2.ADR;work:;;Test Road;Test City;;Test Postcode;Test Country', 'item1.ADR;TYPE=home,pref:;;Pref Test Road;Pref Test City;;Pref Test Postcode;Pref Test Country', 'VERSION:3.0', 'FN:T-firstname T-surname', 'END:VCARD', ); ####### # Test new() ####### my $adbk = Text::vCard::Addressbook->new( { 'source_file' => 't/apple_version3.vcf' } ); my $vcf = $adbk->export(); #print $vcf; like( $vcf, qr/TYPE=work/, 'export() - added type def' ); my @lines = split( "\r\n", $vcf ); is( $lines[0], 'BEGIN:VCARD', 'export() - First line correct' ); is( $lines[$#lines], 'END:VCARD', 'export() - Last line correct' ); $adbk->set_encoding('utf-8'); @data = ( 'BEGIN:VCARD', 'item1.X-ABADR;charset=utf-8:uk', 'item2.X-ABADR;charset=utf-8:uk', 'N;charset=utf-8:T-surname;T-first;;;', 'TEL;charset=utf-8;TYPE=home,pref:020 666 6666', 'TEL;charset=utf-8;TYPE=cell:0777 777 7777', 'item2.ADR;charset=utf-8;TYPE=work:;;Test Road;Test City;;Test Postcode;Test Country', 'item1.ADR;charset=utf-8;TYPE=home,pref:;;Pref Test Road;Pref Test City;;Pref Test Postcode;Pref Test Country', 'VERSION;charset=utf-8:3.0', 'FN;charset=utf-8:T-firstname T-surname', 'END:VCARD', ); @lines = split( "\r\n", $adbk->export() ); 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\r\n$}, '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; } 07-quoted.t100644000765000024 106112064665273 14732 0ustar00leostaff000000000000Text-vCard-2.13/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 134212064665273 14520 0ustar00leostaff000000000000Text-vCard-2.13/t#!/usr/bin/perl -w use strict; use lib qw(./lib); use Digest; use Test::More tests => 5; 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' ); # open my $fh, '>/tmp/victoly.gif'; # binmode $fh; # print $fh $photo->value; # close $fh; my $match = 'f80d7eda8ae7fd34eac2cc9f05dee6d5615a40d48e69f4541f7eb4f9bba050b7'; my $ctx = Digest->new('SHA-256'); $ctx->add( $photo->value ); is( $ctx->hexdigest, $match, 'SHA-256 sum of photo matches' ); 04-formats.t100644000765000024 230312064665273 15101 0ustar00leostaff000000000000Text-vCard-2.13/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' ); encoding.vcf100644000765000024 44012064665273 15266 0ustar00leostaff000000000000Text-vCard-2.13/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 50312064665273 15336 0ustar00leostaff000000000000Text-vCard-2.13/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:FOO06-encoding.t100644000765000024 153512064665273 15224 0ustar00leostaff000000000000Text-vCard-2.13/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\r\n333 West River Park Drive", 'Match on street' ); is( $a->city(), 'Provo', 'Match on city' ); evolution.vcf100644000765000024 22312064665273 15523 0ustar00leostaff000000000000Text-vCard-2.13/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 012064665273 14111 5ustar00leostaff000000000000Text-vCard-2.13/libvCard.pm100644000765000024 3565012064665273 15677 0ustar00leostaff000000000000Text-vCard-2.13/lib/Textpackage Text::vCard; { $Text::vCard::VERSION = '2.13'; } use 5.006; use Carp; use strict; use warnings; use File::Slurp 9999.04; 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 TZ 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 - a package to edit and create a single vCard (RFC 2426) =head1 WARNING To handle a whole addressbook with several vCard entries in it, you probably want to start with L, then this module. =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 ); 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, $charset ) = @_; # derp my %e = map { lc $_ => 1 } @{ $fields || [] }; my @k = qw(VERSION N FN); if ($fields) { push @k, map { uc $_ } @$fields; } else { push @k, grep { defined $_ and $_ ne '' and $_ !~ /^(VERSION|N|FN)$/ } map { uc $_ } keys %{ $self->{nodes} }; } my @lines = qw(BEGIN:VCARD); for my $k (@k) { next unless $k; next unless my $nodes = $self->get($k); push @lines, map { $_->as_string($charset) } @{$nodes}; } return join "\x0d\x0a", @lines, 'END:VCARD', ''; } 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} || '', } ); 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 =head1 BUGS None that I'm aware of - export may not encode correctly. =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 =cut 1; 03-addressbook.t100644000765000024 402012064665273 15723 0ustar00leostaff000000000000Text-vCard-2.13/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 45012064665273 16147 0ustar00leostaff000000000000Text-vCard-2.13/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; use Test::More; eval 'use Test::NoTabs'; plan skip_all => 'Test::NoTabs required' if $@; all_perl_files_ok(); apple_version3.vcf100644000765000024 53212064665273 16433 0ustar00leostaff000000000000Text-vCard-2.13/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 vCard000755000765000024 012064665273 15150 5ustar00leostaff000000000000Text-vCard-2.13/lib/TextNode.pm100644000765000024 3462212064665273 16562 0ustar00leostaff000000000000Text-vCard-2.13/lib/Text/vCardpackage Text::vCard::Node; { $Text::vCard::Node::VERSION = '2.13'; } use strict; use warnings; use Carp; use Encode; use MIME::Base64 3.07; use MIME::QuotedPrint 3.07; 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->{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') ) { $conf->{'data'}->{'value'} = MIME::QuotedPrint::decode( $conf->{data}{value} ); } # do this first if ( $self->is_type('b') or $self->is_type('base64') ) { # XXX apparently it's possible to get 'b' for 'base64' $conf->{data}{value} = MIME::Base64::decode( $conf->{data}{value} ); # 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' ) { # cover ORG where unit is a list $self->{'name'} = shift(@elements); $self->{'unit'} = \@elements if scalar(@elements) > 0; } # no need for explicit scalar elsif ( @elements <= @{ $self->{field_order} } ) { # set the field values as the data # e.g. $self->{street} = 'The street' @{$self}{ @{ $self->{field_order} } } = @elements; } else { carp sprintf( 'Data value had %d elements expecting %d or less.', scalar @elements, scalar @{ $self->{field_order} } ); } } } } return $self; } =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}; @types = sort keys %{ $self->{params} }; 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 "Prefered node"; } This method is the same as is_type (which can take a value of 'pref') but it specific to if it is the prefered node. This method is used to sort when returning lists of nodes. =cut sub is_pref { my $self = shift; if ( defined $self->{params} && defined $self->{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($_) } = 1 } @{$type}; } else { $self->{params}->{ lc($type) } = 1; } } =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() 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, $charset ) = @_; my %t; for my $t ( $self->types ) { my $backwards = uc $self->is_type($t); $t{$backwards} ||= []; push @{ $t{$backwards} }, uc $t; } # override charset $t{CHARSET} = [$charset] if $charset; # you know it would probably make sense to do some Encode stuff, # plus qp/base64 logic here. my $n = $self->group ? sprintf( '%s.%s', $self->group, $self->node_type ) : $self->node_type; return join ';', $n, map { sprintf( '%s=%s', $_, join ',', @{ $t{$_} } ) } sort keys %t; } sub _escape { my $val = shift; # cover all the bases my %esc = ( "\x0a" => 'n', "\x0d" => 'n', "\x0d\x0a" => 'n' ); $val =~ s/([\\;,]|\x0d?\x0a|\x0d)/sprintf("\\%s", $esc{$1}||$1)/ge; $val; } sub _value_as_string { my ( $self, $charset, $key ) = @_; $charset ||= 'utf-8'; my @fields; for my $f ( @{ $self->{field_order} } ) { next unless defined( my $v = $self->{$f} ); my $data = ''; if ( ref $v eq 'ARRAY' ) { $data = join ',', map { _escape( Encode::encode( $charset, $_ ) ) } @$v; } # assuming the same 'q' for quoted-printable elsif ( $self->is_type('q') or $self->is_type('quoted-printable') ) { # have to reimplement the m:qp line wrap >:| my $enc = MIME::QuotedPrint::encode( Encode::encode( $charset, $v ), '' ); # 74 because minus initial space and terminal = my @lines; my $step = 74 - length $key; # 75 - key + : my ( $i, $len ) = ( 0, length $enc ); while ( $i <= $len ) { # special case if step is initially negative, i.e. if # the key is longer than 76 chars if ( $step < 0 ) { $step = 74; $data = "=\x0d\x0a "; } my $line = substr( $enc, $i, $step ); my ( $a, $b ) = ( $line =~ /(.*?)(=[0-9A-Fa-f]?)$/ ); $line = $a if defined $a; push @lines, $line if length $line; # this says increase the step minus a partial escaped # character $i += $step - length( $b || 0 ); # from now own, step is 74 $step = 74; } $data .= join "=\x0d\x0a ", @lines; } elsif ( $self->is_type('b') or $self->is_type('base64') ) { # also this. it would be nice to be able to set the width # in a parameter. my $enc = MIME::Base64::encode( $v, '' ); my @lines = ''; for ( my $i = 0; $i <= length $enc; $i += 72 ) { push @lines, ' ' . substr( $enc, $i, 72 ); } $data = join "\x0d\x0a", @lines; } else { $data = _escape( Encode::encode( $charset, $v ) ); } push @fields, $data; } join ';', @fields; } sub _fold { my $str = shift; # already folded return $str if $str =~ /\x0d?\x0a/; my @lines; my ( $i, $len, $step ) = ( 0, length $str, 76 ); while ( $i <= $len ) { my $line = substr( $str, $i, $step ); push @lines, $line; # increment the position $i += $step; # step is 75 from now on $step = 75; } join "\x0d\x0a ", @lines; } sub as_string { my ( $self, $charset ) = @_; my $key = $self->_key_as_string($charset); my $val = $self->_value_as_string( $charset, $key ); return _fold("$key:$val"); } # 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). =head2 EXPORT None by default. =head1 AUTHOR Leo Lapworth, LLAP@cuckoo.org =head1 SEE ALSO L L =cut 1; release-pod-syntax.t100644000765000024 45012064665273 16712 0ustar00leostaff000000000000Text-vCard-2.13/t#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use Test::More; eval "use Test::Pod 1.41"; plan skip_all => "Test::Pod 1.41 required for testing POD" if $@; all_pod_files_ok(); apple_2.1_unicode.vcf100644000765000024 41312064665273 16667 0ustar00leostaff000000000000Text-vCard-2.13/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 Addressbook.pm100644000765000024 1767612064665273 20147 0ustar00leostaff000000000000Text-vCard-2.13/lib/Text/vCardpackage Text::vCard::Addressbook; { $Text::vCard::Addressbook::VERSION = '2.13'; } use Carp; use strict; use warnings; use File::Slurp; 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 - a package to parse, edit and create multiple vCards (RFC 2426) =head1 SYNOPSIS To read an existing file: use Text::vCard::Addressbook; my $address_book = Text::vCard::Addressbook->new( { 'source_file' => '/path/to/address.vcf', } ); foreach my $vcard ( $address_book->vcards() ) { print "Got card for " . $vcard->fullname() . "\n"; } To create a new file: use Text::vCard::Addressbook; my $address_book = Text::vCard::Addressbook->new(); my $vcard = $ab->add_vcard; $vcard->fullname('Foo Bar'); $vcard->EMAIL('foo@bar.com'); open my $out, '>', 'address.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 READING IN VCARDS =head2 load() use Text::vCard::Addressbook; # Read in from a list of files my $address_book = Text::vCard::Addressbook->load( [ 'foo.vCard', 'Addresses.vcf' ] ); This method will croak if it is unable to read in any of the files. =cut sub load { my ( $proto, $files ) = @_; my $self = __PACKAGE__->new(); foreach my $file ( @{$files} ) { croak "Unable to read file $file" unless -r $file; $self->import_data( scalar read_file($file) ); } return $self; } =head2 import_data() $address_book->import_data($value); This method imports data directly from a string. =cut sub import_data { my ( $self, $value ) = @_; $self->_process_text($value); } =head2 new() # Read in from just one file my $address_book = Text::vCard::Addressbook->new( { 'source_file' => '/path/to/address.vcf', } ); This method will croak if it is unable to read in the source_file. # File already in a string my $address_book = Text::vCard::Addressbook->new( { 'source_text' => $source_text, } ); # Create a new address book my $address_book = Text::vCard::Addressbook->new(); Looping through all vcards in an address book. foreach my $vcard ( $address_book->vcards() ) { $vcard->...; } =cut sub new { my ( $proto, $conf ) = @_; my $class = ref($proto) || $proto; my $self = {}; if ( defined $conf->{'source_file'} ) { # Need to read in source file croak "Unable to read file $conf->{'source_file'}\n" unless -r $conf->{'source_file'}; $conf->{'source_text'} = read_file( $conf->{'source_file'} ); } # create some where to store out individual vCard objects my @cards; $self->{'cards'} = \@cards; bless( $self, $class ); # Process the text if we have it. $self->_process_text( $conf->{'source_text'} ) if defined $conf->{'source_text'}; return $self; } =head1 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(); 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() $address_book->set_encoding('utf-8'); This method will add the string ';charset=utf-8' to each and every vCard entry. That does help in connection with e.g. an iPhone... =cut sub set_encoding { my ( $self, $coding ) = @_; $self->{'encoding'} |= ''; $self->{'encoding'} = ";charset=$coding" if ( defined $coding ); return $self->{'encoding'}; } =head2 export() my $vcf_file = $address_book->export() This method returns the vcard data 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. This might not escape the results correctly at the moment. =cut sub export { my $self = shift; my @lines; foreach my $vcard ( $self->vcards() ) { push @lines, 'BEGIN:VCARD'; while ( my ( $node_type, $nodes ) = each %{ $vcard->{nodes} } ) { # Make sure all the nodes values are up to date my @export_nodes; foreach my $node ( @{$nodes} ) { my $name = $node_type; if ( $node->group() ) { # Add the group in to the name $name = $node->group() . '.' . $node_type; } my $param; $param = join( ',', ( $node->types() ) ) if $node->types(); $name .= $self->set_encoding(); $name .= ";TYPE=$param" if $param; push( @lines, "$name:" . $node->export_data ); } } push @lines, 'END:VCARD'; } my $vcf_file = join( "\r\n", @lines ); $vcf_file .= "\r\n" if $vcf_file; return $vcf_file; } # PRIVATE METHODS # Process a chunk of text, create Text::vCard objects and store in the address book sub _process_text { my ( $self, $text ) = @_; # As data may handle \r - must ask richard $text =~ s/\r//g; 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) my $joinline = 0; my $out; foreach my $line ( split( "\n", $text ) ) { chomp($line); if ($joinline) { if ( $line =~ /=$/ ) { $line =~ s/=$//; $out .= $line; } else { $joinline = 0; $out .= $line . "\n"; } next; } # find continued QP lines - could be done better if ( $line =~ /ENCODING=QUOTED-PRINTABLE/i && $line =~ /=$/ ) { $joinline = 1; # join lines... $line =~ s/=$//; $out .= $line; } else { # add regular line; $out .= $line . "\n"; } } $text = $out; } # Add error checking here ? my $asData = Text::vFile::asData->new; $asData->preserve_params(1); my $data = $asData->parse_lines( split( "\n", $text ) ); foreach my $card ( @{ $data->{'objects'} } ) { # Run through each card in the data if ( $card->{'type'} =~ /VCARD/i ) { my $vcard = Text::vCard->new( { 'asData_node' => $card->{'properties'}, } ); push( @{ $self->{'cards'} }, $vcard ); } else { carp "This file contains $card->{'type'} data which was not parsed"; } } } =head1 AUTHOR Leo Lapworth, LLAP@cuckoo.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;