CONTRIBUTING000664001750001750 614612406373424 13631 0ustar00taitai000000000000RDF-vCard-0.012NAME CONTRIBUTING DESCRIPTION If you're reading this document, that means you might be thinking about helping me out with this project. Thanks! Here's some ways you could help out: * Bug reports Found a bug? Great! (Well, not so great I suppose.) The place to report them is . Don't e-mail me about it, as your e-mail is more than likely to get lost amongst the spam. An example script clearly demonstrating the bug (preferably written using Test::More) would be greatly appreciated. * Patches If you've found a bug and written a fix for it, even better! Generally speaking you should check out the latest copy of the code from the source repository rather than using the CPAN distribution. The file META.yml should contain a link to the source repository. If not, then try or submit a bug report. (As far as I'm concerned the lack of a link is a bug.) Many of my distributions are also mirrored at . To submit the patch, do a pull request on GitHub or Bitbucket, or attach a diff file to a bug report. Unless otherwise stated, I'll assume that your contributions are licensed under the same terms as the rest of the project. (If using git, feel free to work in a branch. For Mercurial, I'd prefer bookmarks within the default branch.) * Documentation If there's anything unclear in the documentation, please submit this as a bug report or patch as above. Non-toy example scripts that I can bundle would also be appreciated. * Translation Translations of documentation would be welcome. For translations of error messages and other strings embedded in the code, check with me first. Sometimes the English strings may not in a stable state, so it would be a waste of time translating them. Coding Style I tend to write using something approximating the Allman style, using tabs for indentation and Unix-style line breaks. * * I nominally encode all source files as UTF-8, though in practice most of them use a 7-bit-safe ASCII-compatible subset of UTF-8. AUTHOR Toby Inkster . COPYRIGHT AND LICENCE Copyright (c) 2012-2014 by Toby Inkster. CONTRIBUTING is available under three different licences permitting its redistribution: the CC-BY-SA_UK-2.0 licence, plus the same licences as Perl itself, which is distributed under the GNU General Public Licence version 1, and the Artistic Licence. This file is licensed under the Creative Commons Attribution-ShareAlike 2.0 UK: England & Wales License. To view a copy of this license, visit . This file is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. COPYRIGHT000664001750001750 244612406373424 13271 0ustar00taitai000000000000RDF-vCard-0.012Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: RDF-vCard Upstream-Contact: Toby Inkster (TOBYINK) Source: https://metacpan.org/release/RDF-vCard Files: README bin/vcard2rdf bin/vcard2xml lib/RDF/vCard.pm lib/RDF/vCard/Entity.pm lib/RDF/vCard/Entity/WithXmlSupport.pm lib/RDF/vCard/Exporter.pm lib/RDF/vCard/Importer.pm lib/RDF/vCard/Line.pm t/01basic.t Copyright: Copyright 2011 Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: CONTRIBUTING INSTALL LICENSE TODO examples/example.vcard examples/example1.pl examples/example2.pl examples/example3.pl Copyright: Unknown License: Unknown Files: Changes META.json META.yml dist.ini doap.ttl Copyright: Copyright 2014 Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: COPYRIGHT CREDITS SIGNATURE Copyright: None License: public-domain Files: Makefile.PL Copyright: Copyright 2013 Toby Inkster. License: GPL-1.0+ or Artistic-1.0 License: Artistic-1.0 This software is Copyright (c) 2014 by the copyright holder(s). This is free software, licensed under: The Artistic License 1.0 License: GPL-1.0 This software is Copyright (c) 2014 by the copyright holder(s). This is free software, licensed under: The GNU General Public License, Version 1, February 1989 CREDITS000664001750001750 7112406373421 12743 0ustar00taitai000000000000RDF-vCard-0.012Maintainer: - Toby Inkster (TOBYINK) Changes000664001750001750 377212406373421 13271 0ustar00taitai000000000000RDF-vCard-0.012RDF-vCard ========= Created: 2011-01-05 Home page: Bug tracker: Maintainer: Toby Inkster (TOBYINK) 0.012 2014-09-17 - no warnings 'uninitialized' 0.011 2014-09-17 [ Packaging ] - Add IRC link. - Switch to Dist::Inkt. [ Other ] - use warnings 0.010 2012-06-23 [ Bug Fixes ] - Fix various small issues around RDF::TrineShortcuts -> RDF::TrineX::Functions switch. 0.009 2012-06-22 [ Packaging ] - Reduce dependencies - no longer need common::sense, RDF::TrineShortcuts (thus RDF::Query) or parent.pm, but do need RDF::TrineX::Functions. - Switch to Module::Package::RDF. 0.008 2011-07-13 - Added: Add support for 'lang' option when converting vCards to RDF. - Added: Include language tags on plain literals, if provided. - Added: Use Content-Language HTTP header of downloaded vCards. - Added: vcard2rdf script. 0.007 2011-02-16 [ Bug Fixes ] - Setting vcard_version to 3 outputted version 4 vcards. [ Other ] - Added: jCard output. 0.006 2011-02-04 [ Bug Fixes ] - Fix WithXmlSupport's string overloading. 0.005 2011-01-30 - Added: Experimental vCard XML support. - Added: Partial vCard 4.0 support. - Added: nvalue method on RDF::vCard::Line. 0.004 2011-01-23 - More flexibility for other classes wanting to subclass this - particularly around different datatypes. 0.003 2011-01-16 Two-way conversions. - Added: Add RDF::vCard::Importer module. - Added: RDF::vCard::Entity now has add_to_model() and node() methods. - Added: RDF::vCard::Line now has an add_to_model() method. 0.002 2011-01-12 - Added: Include vCard VERSION property in output. - Improved support for 'data:' URIs in binary vCard properties. - More consistent support for comma-escaping. - Proper support for vCard CATEGORIES property. - Support for RDF vCard 2006 v:homeTel property and its ilk. - Tidied up export_card method. 0.001 2011-01-06 Initial release. RDF to vCard only. INSTALL000664001750001750 165312406373420 13022 0ustar00taitai000000000000RDF-vCard-0.012 Installing RDF-vCard should be straightforward. INSTALLATION WITH CPANMINUS If you have cpanm, you only need one line: % cpanm RDF::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 RDF::vCard INSTALLATION WITH THE CPAN SHELL Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan RDF::vCard MANUAL INSTALLATION As a last resort, you can manually install it. Download the tarball and unpack it. Consult the file META.json for a list of pre-requisites. Install these first. To build RDF-vCard: % 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 LICENSE000664001750001750 4365512406373420 13026 0ustar00taitai000000000000RDF-vCard-0.012This software is copyright (c) 2014 by Toby Inkster. 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) 2014 by Toby Inkster. 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, Fifth Floor, Boston, MA 02110-1301 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) 2014 by Toby Inkster. 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 MANIFEST000664001750001750 63712406373424 13107 0ustar00taitai000000000000RDF-vCard-0.012CONTRIBUTING COPYRIGHT CREDITS Changes INSTALL LICENSE MANIFEST META.json META.yml Makefile.PL README SIGNATURE TODO bin/vcard2rdf bin/vcard2xml dist.ini doap.ttl examples/example.vcard examples/example1.pl examples/example2.pl examples/example3.pl lib/RDF/vCard.pm lib/RDF/vCard/Entity.pm lib/RDF/vCard/Entity/WithXmlSupport.pm lib/RDF/vCard/Exporter.pm lib/RDF/vCard/Importer.pm lib/RDF/vCard/Line.pm t/01basic.t META.json000664001750001750 535512406373424 13421 0ustar00taitai000000000000RDF-vCard-0.012{ "abstract" : "convert between RDF and vCard", "author" : [ "Toby Inkster (TOBYINK) " ], "dynamic_config" : 0, "generated_by" : "Dist::Inkt::Profile::TOBYINK version 0.023, CPAN::Meta::Converter version 2.140640", "keywords" : [ "Contacts", "Directory", "RDF", "SemWeb", "Semantic Web", "XML", "hCard", "vCard" ], "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "RDF-vCard", "no_index" : { "directory" : [ "eg", "examples", "inc", "t", "xt" ] }, "optional_features" : {}, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.17" } }, "runtime" : { "requires" : { "RDF::Trine" : "0.135", "RDF::TrineX::Functions" : "0", "Text::vFile::asData" : "0.07", "URI" : "0", "XML::LibXML" : "1.70", "namespace::clean" : "0", "perl" : "5.008" } }, "test" : { "requires" : { "Test::More" : "0.61" } } }, "provides" : { "RDF::vCard" : { "file" : "lib/RDF/vCard.pm", "version" : "0.012" }, "RDF::vCard::Entity" : { "file" : "lib/RDF/vCard/Entity.pm", "version" : "0.012" }, "RDF::vCard::Entity::WithXmlSupport" : { "file" : "lib/RDF/vCard/Entity/WithXmlSupport.pm", "version" : "0.012" }, "RDF::vCard::Exporter" : { "file" : "lib/RDF/vCard/Exporter.pm", "version" : "0.012" }, "RDF::vCard::Importer" : { "file" : "lib/RDF/vCard/Importer.pm", "version" : "0.012" }, "RDF::vCard::Line" : { "file" : "lib/RDF/vCard/Line.pm", "version" : "0.012" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "http://rt.cpan.org/Dist/Display.html?Queue=RDF-vCard" }, "homepage" : "https://metacpan.org/release/RDF-vCard", "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "type" : "git", "url" : "git://github.com/tobyink/p5-rdf-vcard.git", "web" : "https://github.com/tobyink/p5-rdf-vcard" }, "x_IRC" : "irc://irc.perl.org/#perlrdf", "x_identifier" : "http://purl.org/NET/cpan-uri/dist/RDF-vCard/project" }, "version" : "0.012", "x_provides_scripts" : { "vcard2rdf" : { "file" : "bin/vcard2rdf" }, "vcard2xml" : { "file" : "bin/vcard2xml" } } } META.yml000664001750001750 327112406373424 13244 0ustar00taitai000000000000RDF-vCard-0.012--- abstract: 'convert between RDF and vCard' author: - 'Toby Inkster (TOBYINK) ' build_requires: Test::More: '0.61' configure_requires: ExtUtils::MakeMaker: '6.17' dynamic_config: 0 generated_by: 'Dist::Inkt::Profile::TOBYINK version 0.023, CPAN::Meta::Converter version 2.140640' keywords: - Contacts - Directory - RDF - SemWeb - 'Semantic Web' - XML - hCard - vCard license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: RDF-vCard no_index: directory: - eg - examples - inc - t - xt optional_features: {} provides: RDF::vCard: file: lib/RDF/vCard.pm version: '0.012' RDF::vCard::Entity: file: lib/RDF/vCard/Entity.pm version: '0.012' RDF::vCard::Entity::WithXmlSupport: file: lib/RDF/vCard/Entity/WithXmlSupport.pm version: '0.012' RDF::vCard::Exporter: file: lib/RDF/vCard/Exporter.pm version: '0.012' RDF::vCard::Importer: file: lib/RDF/vCard/Importer.pm version: '0.012' RDF::vCard::Line: file: lib/RDF/vCard/Line.pm version: '0.012' requires: RDF::Trine: '0.135' RDF::TrineX::Functions: '0' Text::vFile::asData: '0.07' URI: '0' XML::LibXML: '1.70' namespace::clean: '0' perl: '5.008' resources: IRC: irc://irc.perl.org/#perlrdf Identifier: http://purl.org/NET/cpan-uri/dist/RDF-vCard/project bugtracker: http://rt.cpan.org/Dist/Display.html?Queue=RDF-vCard homepage: https://metacpan.org/release/RDF-vCard license: http://dev.perl.org/licenses/ repository: git://github.com/tobyink/p5-rdf-vcard.git version: '0.012' x_provides_scripts: vcard2rdf: file: bin/vcard2rdf vcard2xml: file: bin/vcard2xml Makefile.PL000664001750001750 1454512406373424 13773 0ustar00taitai000000000000RDF-vCard-0.012use strict; use ExtUtils::MakeMaker 6.17; my $EUMM = eval( $ExtUtils::MakeMaker::VERSION ); my $meta = { "abstract" => "convert between RDF and vCard", "author" => ["Toby Inkster (TOBYINK) "], "dynamic_config" => 0, "generated_by" => "Dist::Inkt::Profile::TOBYINK version 0.023, CPAN::Meta::Converter version 2.140640", "keywords" => [ "Contacts", "Directory", "RDF", "SemWeb", "Semantic Web", "XML", "hCard", "vCard", ], "license" => ["perl_5"], "meta-spec" => { url => "http://search.cpan.org/perldoc?CPAN::Meta::Spec", version => 2, }, "name" => "RDF-vCard", "no_index" => { directory => ["eg", "examples", "inc", "t", "xt"] }, "prereqs" => { configure => { requires => { "ExtUtils::MakeMaker" => 6.17 } }, runtime => { requires => { "namespace::clean" => 0, "perl" => 5.008, "RDF::Trine" => 0.135, "RDF::TrineX::Functions" => 0, "Text::vFile::asData" => 0.07, "URI" => 0, "XML::LibXML" => "1.70", }, }, test => { requires => { "Test::More" => 0.61 } }, }, "provides" => { "RDF::vCard" => { file => "lib/RDF/vCard.pm", version => 0.012 }, "RDF::vCard::Entity" => { file => "lib/RDF/vCard/Entity.pm", version => 0.012 }, "RDF::vCard::Entity::WithXmlSupport" => { file => "lib/RDF/vCard/Entity/WithXmlSupport.pm", version => 0.012 }, "RDF::vCard::Exporter" => { file => "lib/RDF/vCard/Exporter.pm", version => 0.012 }, "RDF::vCard::Importer" => { file => "lib/RDF/vCard/Importer.pm", version => 0.012 }, "RDF::vCard::Line" => { file => "lib/RDF/vCard/Line.pm", version => 0.012 }, }, "release_status" => "stable", "resources" => { bugtracker => { web => "http://rt.cpan.org/Dist/Display.html?Queue=RDF-vCard" }, homepage => "https://metacpan.org/release/RDF-vCard", license => ["http://dev.perl.org/licenses/"], repository => { type => "git", url => "git://github.com/tobyink/p5-rdf-vcard.git", web => "https://github.com/tobyink/p5-rdf-vcard", }, x_identifier => "http://purl.org/NET/cpan-uri/dist/RDF-vCard/project", x_IRC => "irc://irc.perl.org/#perlrdf", }, "version" => 0.012, "x_provides_scripts" => { vcard2rdf => { file => "bin/vcard2rdf" }, vcard2xml => { file => "bin/vcard2xml" }, }, }; my %dynamic_config; my %WriteMakefileArgs = ( ABSTRACT => $meta->{abstract}, AUTHOR => ($EUMM >= 6.5702 ? $meta->{author} : $meta->{author}[0]), DISTNAME => $meta->{name}, VERSION => $meta->{version}, EXE_FILES => [ map $_->{file}, values %{ $meta->{x_provides_scripts} || {} } ], NAME => do { my $n = $meta->{name}; $n =~ s/-/::/g; $n }, test => { TESTS => "t/*.t" }, %dynamic_config, ); $WriteMakefileArgs{LICENSE} = $meta->{license}[0] if $EUMM >= 6.3001; sub deps { my %r; for my $stage (@_) { for my $dep (keys %{$meta->{prereqs}{$stage}{requires}}) { next if $dep eq 'perl'; my $ver = $meta->{prereqs}{$stage}{requires}{$dep}; $r{$dep} = $ver if !exists($r{$dep}) || $ver >= $r{$dep}; } } \%r; } my ($build_requires, $configure_requires, $runtime_requires, $test_requires); if ($EUMM >= 6.6303) { $WriteMakefileArgs{BUILD_REQUIRES} ||= deps('build'); $WriteMakefileArgs{CONFIGURE_REQUIRES} ||= deps('configure'); $WriteMakefileArgs{TEST_REQUIRES} ||= deps('test'); $WriteMakefileArgs{PREREQ_PM} ||= deps('runtime'); } elsif ($EUMM >= 6.5503) { $WriteMakefileArgs{BUILD_REQUIRES} ||= deps('build', 'test'); $WriteMakefileArgs{CONFIGURE_REQUIRES} ||= deps('configure'); $WriteMakefileArgs{PREREQ_PM} ||= deps('runtime'); } elsif ($EUMM >= 6.52) { $WriteMakefileArgs{CONFIGURE_REQUIRES} ||= deps('configure'); $WriteMakefileArgs{PREREQ_PM} ||= deps('runtime', 'build', 'test'); } else { $WriteMakefileArgs{PREREQ_PM} ||= deps('configure', 'build', 'test', 'runtime'); } { my ($minperl) = reverse sort( grep defined && /^[0-9]+(\.[0-9]+)?$/, map $meta->{prereqs}{$_}{requires}{perl}, qw( configure build runtime ) ); if (defined($minperl)) { die "Installing $meta->{name} requires Perl >= $minperl" unless $] >= $minperl; $WriteMakefileArgs{MIN_PERL_VERSION} ||= $minperl if $EUMM >= 6.48; } } sub FixMakefile { return unless -d 'inc'; my $file = shift; local *MAKEFILE; open MAKEFILE, "< $file" or die "FixMakefile: Couldn't open $file: $!; bailing out"; my $makefile = do { local $/; }; close MAKEFILE or die $!; $makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /; $makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g; $makefile =~ s/( "-I\$\(INST_LIB\)")/ "-Iinc"$1/g; $makefile =~ s/^(FULLPERL = .*)/$1 "-Iinc"/m; $makefile =~ s/^(PERL = .*)/$1 "-Iinc"/m; open MAKEFILE, "> $file" or die "FixMakefile: Couldn't open $file: $!; bailing out"; print MAKEFILE $makefile or die $!; close MAKEFILE or die $!; } my $mm = WriteMakefile(%WriteMakefileArgs); FixMakefile($mm->{FIRST_MAKEFILE} || 'Makefile'); exit(0); README000664001750001750 353512406373420 12652 0ustar00taitai000000000000RDF-vCard-0.012NAME RDF::vCard - convert between RDF and vCard SYNOPSIS use RDF::vCard; use RDF::TrineShortcuts qw(rdf_string); my $input = "http://example.com/contact-data.rdf"; my $exporter = RDF::vCard::Exporter->new; my $data = join '', $exporter->export_cards($input); print $data; # vCard 3.0 data my $importer = RDF::vCard::Importer->new; $importer->import_string($data); print rdf_string($importer->model => 'RDFXML'); DESCRIPTION This module doesn't do anything itself; it just loads RDF::vCard::Exporter and RDF::vCard::Importer for you. RDF::vCard::Exporter RDF::vCard::Exporter takes some RDF using the W3C's vCard vocabulary, and outputs RDF::vCard::Entity objects. RDF::vCard::Importer RDF::vCard::Importer does the reverse. RDF::vCard::Entity An RDF::vCard::Entity objects is an individual vCard. It overloads stringification, so just treat it like a string. RDF::vCard::Entity::WithXmlSupport RDF::vCard::Entity::WithXmlSupport is a subclass of RDF::vCard::Entity, with a `to_xml` method. It requires XML::LibXML to be installed and working. The importer and exporter will try to create these if possible. RDF::vCard::Line RDF::vCard::Line is internal fu that you probably don't want to touch. BUGS If your RDF asserts that Alice is Bob's AGENT and Bob is Alice's AGENT, then RDF::vCard::Export will eat your face. Don't do it. Please report any other bugs to . SEE ALSO . . RDF::vCard::Babelfish. AUTHOR Toby Inkster . COPYRIGHT Copyright 2011 Toby Inkster This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SIGNATURE000664001750001750 447212406373424 13263 0ustar00taitai000000000000RDF-vCard-0.012This file contains message digests of all files listed in MANIFEST, signed via the Module::Signature module, version 0.73. To verify the content in this distribution, first make sure you have Module::Signature installed, then type: % cpansign -v It will check each file's integrity, as well as the signature's validity. If "==> Signature verified OK! <==" is not displayed, the distribution may already have been compromised, and you should not run its Makefile.PL or Build.PL. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 SHA1 33317486c4fa2cf7fec85bf92ed38ac0f64233a0 CONTRIBUTING SHA1 c277d63b48b7a67e6ab94c560590567a56ab18ad COPYRIGHT SHA1 6bd7b17d81be63d08d4efa6cb80106e72887842c CREDITS SHA1 7f0baf77542d0b631549c1c26da77baaad16a7ad Changes SHA1 79af6bf3dd69bafed0e98e8e71549ab84fd18df1 INSTALL SHA1 34f5e12514b91055de4b164a1f2327ef5c30ba53 LICENSE SHA1 b993344ea20d6a244512680f43c8bedb560c7dcf MANIFEST SHA1 c115b9bcce91fe61d947e9a206c87f820de7b85f META.json SHA1 b26b3d443474ec06eebe26837d7ad79abf843832 META.yml SHA1 a94a4008ff4b43a7b30a9701e1550e12cb511990 Makefile.PL SHA1 a65e427c26dcf35a6dd9fa52da564f043d929318 README SHA1 2c73701575eea819b4ce599c67436e446731d180 TODO SHA1 0926bce06bccb7c038d7a2af4b3572b957789a75 bin/vcard2rdf SHA1 4c78b0f3419a570c8519340f7f93bb4ab10ada33 bin/vcard2xml SHA1 578c212da16c2f8a36db089f3901102dd81d7b4f dist.ini SHA1 f957b4fdf6d18844069dd6934550fdc5961e585a doap.ttl SHA1 05603de07e9235f261a7b890a6382f578d9272e0 examples/example.vcard SHA1 ca1ed448298bbafe26b36bb492b00685a7988bd8 examples/example1.pl SHA1 52fa14b4b07dc76ed895a6ef4521c22754ae9f80 examples/example2.pl SHA1 8a1eff5ffb39e50ad73cb12dbebcc4f1a682b7a0 examples/example3.pl SHA1 cc90aa9769a7d7dd73589677c423dc7c45f05089 lib/RDF/vCard.pm SHA1 6fbe152f5e35997b2cb6e90c331d9d3e187d5e43 lib/RDF/vCard/Entity.pm SHA1 94c0b0c3cc07a00b67705a0815f1e8ab85430994 lib/RDF/vCard/Entity/WithXmlSupport.pm SHA1 a2030bec7c586b02e2feae9ff33032ec9729a97a lib/RDF/vCard/Exporter.pm SHA1 f0fca94644c1acb3314f2b196b53a1747d8f03eb lib/RDF/vCard/Importer.pm SHA1 43260c3bc142cca7cc97f2c661cfc6ea37ec95d1 lib/RDF/vCard/Line.pm SHA1 87aa60dd374d9627ee83f929d987483a5503a7e4 t/01basic.t -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAlQZ9xQACgkQzr+BKGoqfTk4zgCdHMTToTXnArDZo+KZYqVZY+EF YukAnibFzANqncYg+jGVxdd6fC0h4XAQ =PJku -----END PGP SIGNATURE----- TODO000664001750001750 3212406373420 12407 0ustar00taitai000000000000RDF-vCard-0.012Need far more test cases. dist.ini000664001750001750 12312406373420 13404 0ustar00taitai000000000000RDF-vCard-0.012;;class='Dist::Inkt::Profile::TOBYINK' ;;name='RDF-vCard' ;;skip_whitespace_test=1 doap.ttl000664001750001750 2520712406373423 13465 0ustar00taitai000000000000RDF-vCard-0.012@prefix cpan-uri: . @prefix dc: . @prefix doap: . @prefix doap-changeset: . @prefix doap-deps: . @prefix foaf: . @prefix owl: . @prefix rdfs: . @prefix xsd: . a doap:Project; cpan-uri:x_IRC ; dc:contributor ; doap-deps:runtime-requirement [ doap-deps:on "perl 5.008"^^doap-deps:CpanId ], [ doap-deps:on "XML::LibXML 1.70"^^doap-deps:CpanId ], [ doap-deps:on "namespace::clean"^^doap-deps:CpanId ], [ doap-deps:on "RDF::Trine 0.135"^^doap-deps:CpanId ], [ doap-deps:on "RDF::TrineX::Functions"^^doap-deps:CpanId; ], [ doap-deps:on "Text::vFile::asData 0.07"^^doap-deps:CpanId; ], [ doap-deps:on "URI"^^doap-deps:CpanId ]; doap-deps:test-requirement [ doap-deps:on "Test::More 0.61"^^doap-deps:CpanId ]; doap:bug-database ; doap:category [ rdfs:label "RDF"@en ], [ rdfs:label "Semantic Web"@en ], [ rdfs:label "SemWeb"@en ], [ rdfs:label "vCard"@en ], [ rdfs:label "Directory"@en ], [ rdfs:label "Contacts"@en ], [ rdfs:label "hCard"@en ], [ rdfs:label "XML"@en ]; doap:created "2011-01-05"^^xsd:date; doap:developer ; doap:documenter ; doap:download-page ; doap:homepage ; doap:license ; doap:maintainer ; doap:name "RDF-vCard"; doap:programming-language "Perl"; doap:release , , , , , , , , , , , ; doap:repository [ a doap:GitRepository; doap:browse ; ]; doap:shortdesc "convert between RDF and vCard"@en; doap:tester . a doap:Version; rdfs:label "Initial release. RDF to vCard only."@en; dc:issued "2011-01-06"^^xsd:date; doap:file-release ; doap:revision "0.001"^^xsd:string. a doap:Version; dc:issued "2011-01-12"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ rdfs:label "Proper support for vCard CATEGORIES property."@en; ], [ rdfs:label "Support for RDF vCard 2006 v:homeTel property and its ilk."@en; ], [ rdfs:label "Improved support for 'data:' URIs in binary vCard properties."@en; ], [ a doap-changeset:Addition; rdfs:label "Include vCard VERSION property in output."@en; ], [ rdfs:label "Tidied up export_card method."@en ], [ rdfs:label "More consistent support for comma-escaping."@en; ]; doap-changeset:versus ; ]; doap:file-release ; doap:revision "0.002"^^xsd:string. a doap:Version; rdfs:label "Two-way conversions."@en; dc:issued "2011-01-16"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Addition; rdfs:label "RDF::vCard::Line now has an add_to_model() method."@en; ], [ a doap-changeset:Addition; rdfs:label "Add RDF::vCard::Importer module."@en; ], [ a doap-changeset:Addition; rdfs:label "RDF::vCard::Entity now has add_to_model() and node() methods."@en; ]; doap-changeset:versus ; ]; doap:file-release ; doap:revision "0.003"^^xsd:string. a doap:Version; dc:issued "2011-01-23"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ rdfs:label "More flexibility for other classes wanting to subclass this - particularly around different datatypes."@en; ]; doap-changeset:versus ; ]; doap:file-release ; doap:revision "0.004"^^xsd:string. a doap:Version; dc:issued "2011-01-30"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Addition; rdfs:label "nvalue method on RDF::vCard::Line."@en; ], [ a doap-changeset:Addition; rdfs:label "Experimental vCard XML support."@en; ], [ a doap-changeset:Addition; rdfs:label "Partial vCard 4.0 support."@en; ]; doap-changeset:versus ; ]; doap:file-release ; doap:revision "0.005"^^xsd:string. a doap:Version; dc:issued "2011-02-04"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Bugfix; rdfs:label "Fix WithXmlSupport's string overloading."@en; ]; doap-changeset:versus ; ]; doap:file-release ; doap:revision "0.006"^^xsd:string. a doap:Version; dc:issued "2011-02-16"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Bugfix; rdfs:label "Setting vcard_version to 3 outputted version 4 vcards."@en; ], [ a doap-changeset:Addition; rdfs:label "jCard output."@en; ]; doap-changeset:versus ; ]; doap:file-release ; doap:revision "0.007"^^xsd:string. a doap:Version; dc:issued "2011-07-13"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Addition; rdfs:label "vcard2rdf script."@en; ], [ a doap-changeset:Addition; rdfs:label "Add support for 'lang' option when converting vCards to RDF."@en; ], [ a doap-changeset:Addition; rdfs:label "Include language tags on plain literals, if provided."@en; ], [ a doap-changeset:Addition; rdfs:label "Use Content-Language HTTP header of downloaded vCards."@en; ]; doap-changeset:versus ; ]; doap:file-release ; doap:revision "0.008"^^xsd:string. a doap:Version; dc:issued "2012-06-22"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Packaging; rdfs:label "Reduce dependencies - no longer need common::sense, RDF::TrineShortcuts (thus RDF::Query) or parent.pm, but do need RDF::TrineX::Functions."@en; ], [ a doap-changeset:Packaging; rdfs:label "Switch to Module::Package::RDF."@en; ]; doap-changeset:versus ; ]; doap:file-release ; doap:revision "0.009"^^xsd:string. a doap:Version; dc:issued "2012-06-23"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Bugfix; rdfs:label "Fix various small issues around RDF::TrineShortcuts -> RDF::TrineX::Functions switch."@en; ]; doap-changeset:versus ; ]; doap:file-release ; doap:revision "0.010"^^xsd:string. a doap:Version; dc:identifier "RDF-vCard-0.011"^^xsd:string; dc:issued "2014-09-17"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Change; rdfs:label "use warnings"; ], [ a doap-changeset:Packaging; rdfs:label "Switch to Dist::Inkt."; ], [ a doap-changeset:Packaging; rdfs:label "Add IRC link."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.011"^^xsd:string. a doap:Version; dc:identifier "RDF-vCard-0.012"^^xsd:string; dc:issued "2014-09-17"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Change; rdfs:label "no warnings 'uninitialized'"; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.012"^^xsd:string. a foaf:Person; foaf:homepage ; foaf:mbox ; foaf:name "Toby Inkster"; foaf:nick "TOBYINK"; foaf:page ; owl:sameAs . vcard2rdf000664001750001750 134412406373420 14336 0ustar00taitai000000000000RDF-vCard-0.012/bin#!/usr/bin/perl use strict; BEGIN { print STDERR "Reading vCard input from STDIN.\n" unless @ARGV; } use RDF::vCard; use RDF::Trine; my $importer = RDF::vCard::Importer->new; unless (@ARGV) { my ($lang) = split /\./, $ENV{LANG}; $lang =~ s/_/-/g; local $/ = undef; my $input = <>; $importer->import_string($input, lang => $lang); } while (my $input = shift @ARGV) { if ($input =~ /^(ftp|http|https|file):/i) { $importer->import_url($input); } else { $importer->import_file($input); } } my $ser = RDF::Trine::Serializer::Turtle->new( namespaces => { v => 'http://www.w3.org/2006/vcard/ns#', vx => 'http://buzzword.org.uk/rdf/vcardx#', }, ); print $ser->serialize_model_to_string($importer->model); vcard2xml000664001750001750 164712406373420 14371 0ustar00taitai000000000000RDF-vCard-0.012/bin#!/usr/bin/perl use strict; BEGIN { print STDERR "Reading vCard input from STDIN.\n" unless @ARGV; } use RDF::vCard; use XML::LibXML; my $importer = RDF::vCard::Importer->new; my @cards; unless (@ARGV) { my ($lang) = split /\./, $ENV{LANG}; $lang =~ s/_/-/g; local $/ = undef; my $input = <>; push @cards, $importer->import_string($input, lang => $lang); } while (my $input = shift @ARGV) { if ($input =~ /^(ftp|http|https|file):/i) { push @cards, $importer->import_url($input); } else { push @cards, $importer->import_file($input); } } my $doc; foreach my $c (@cards) { if ($doc) { $c->add_to_document($doc); } else { die "No XML support available (please install XML::LibXML)\n" unless $c->can('to_xml'); # Kinda annoying that we only get it as a string, and then need to parse it as XML. :-( $doc = XML::LibXML->new->parse_string($c->to_xml); } } printf("%s\n", $doc->toString) if $doc;example.vcard000664001750001750 14312406373420 16234 0ustar00taitai000000000000RDF-vCard-0.012/examplesBEGIN:VCARD fn:Toby Inkster note;lang=en:This is a test. END:VCARD BEGIN:VCARD fn:Test 2 END:VCARD example1.pl000664001750001750 476112406373420 15663 0ustar00taitai000000000000RDF-vCard-0.012/examplesuse RDF::TrineX::Functions -shortcuts; use HTML::Microformats; use RDF::vCard; use JSON -convert_blessed_universally; my $html = <<'HTML'; Example

Alice Jones

Lewes, East Sussex (50.87363;0.01133)

Secretary
Updated: 2011-01-06T11:00:00Z
HTML my $doc = HTML::Microformats->new_document($html, "http://example.com/", type=>'application/xhtml+xml')->assume_all_profiles; my $model = rdf_parse(<<'MORE', type=>'turtle', model => $doc->model, base => 'http://example.net/base/'); @prefix rdf: . @prefix v: . @prefix vx: . rdf:value "Quux" . a v:VCard ; v:fn "Example.Com LLC"@en ; v:org [ v:organisation-name "Example.Com LLC" ; v:organisation-unit "Corporate Division" ] ; vx:category , ; v:category "Corporate", "Foobar"; v:logo ; v:homeAdr [ a v:Work ; v:country-name "Australia" ; v:locality "WonderLand", "WonderCity" ; v:postal-code "5555" ; v:street-address "33 Enterprise Drive" ] ; v:geo [ v:latitude "43.33" ; v:longitude "55.45" ] ; v:tel [ a v:Fax, v:Work , v:Pref ; rdf:value "+61 7 5555 0000" ] ; v:email ; v:logo . MORE #print rdf_string($model => 'rdfxml'); #print "#######\n"; my $exporter = RDF::vCard::Exporter->new(vcard_version=>4); my @cards = $exporter->export_cards($model); foreach my $c (@cards) { print $c; print "\n"; print $c->to_xml; print "\n"; print "\n"; } example2.pl000664001750001750 476612406373420 15671 0ustar00taitai000000000000RDF-vCard-0.012/examplesuse Data::Dumper; use RDF::TrineX::Functions -shortcuts; use HTML::Microformats; use RDF::vCard; use RDF::vCard::Importer; use JSON -convert_blessed_universally; my $html = <<'HTML'; Example

Alice Jones

Lewes, East Sussex

Secretary
Updated: 2011-01-06T11:00:00Z
HTML my $doc = HTML::Microformats->new_document($html, "http://example.com/", type=>'application/xhtml+xml')->assume_all_profiles; my $model = rdf_parse(<<'MORE', type=>'turtle', model => $doc->model, base => 'http://example.net/base/'); @prefix rdf: . @prefix v: . @prefix vx: . rdf:value "Quux" . a v:VCard ; v:fn "Example.Com LLC" ; v:org [ v:organisation-name "Dewey, Cheatem and Howe" ; v:organisation-unit "Corporate Division" ] ; vx:category , ; v:category "Corporate", "Foobar"; v:logo ; v:homeAdr [ a v:Work ; v:country-name "Australia" ; v:locality "WonderLand", "WonderCity" ; v:postal-code "5555" ; v:street-address "33 Enterprise Drive" ] ; v:geo [ v:latitude "43.33" ; v:longitude "55.45" ] ; v:tel [ a v:Fax, v:Work ; rdf:value "+61 7 5555 0000" ] ; v:email ; v:logo . MORE my $exporter = RDF::vCard::Exporter->new; my @cards = $exporter->export_cards($model); my $cards = join "", @cards; my $importer = RDF::vCard::Importer->new; my @rv = $importer->import_string($cards); print $cards; print Dumper([ @rv ]); print rdf_string($importer->model => 'RDFXML'); example3.pl000664001750001750 41412406373420 15634 0ustar00taitai000000000000RDF-vCard-0.012/examples#!/usr/bin/perl use strict; use RDF::vCard; use Data::Dumper; my $vc = <new; my @cards = $i->import_string($vc, lang=>'en'); print Dumper(@cards); 01basic.t000664001750001750 127112406373420 13637 0ustar00taitai000000000000RDF-vCard-0.012/tuse Test::More tests => 6; BEGIN { use_ok('RDF::vCard') }; ok( RDF::vCard::Importer->can('new'), "RDF::vCard::Importer can be instantiated.", ); ok( RDF::vCard::Exporter->can('new'), "RDF::vCard::Exporter can be instantiated.", ); ok( RDF::vCard::Line->can("new"), "RDF::vCard::Line can be instantiated.", ); my $line = RDF::vCard::Line->new( property => "email", value => "joe\@example.net", type_parameters => { type=>[qw(PREF INTERNET)] }, ); is( "$line", "EMAIL;TYPE=PREF,INTERNET:joe\@example.net", "Lines seem formatted correctly.", ); my $card = RDF::vCard::Entity->new; $card->add($line); ok( "$card" =~ /example.net/, "Cards seem to work.", ); vCard.pm000664001750001750 445312406373420 14550 0ustar00taitai000000000000RDF-vCard-0.012/lib/RDFpackage RDF::vCard; use 5.008; use strict; use warnings; no warnings qw(uninitialized); use RDF::vCard::Entity; use RDF::vCard::Exporter; use RDF::vCard::Importer; our $VERSION = '0.012'; our $WITH_XML; BEGIN { local $@ = undef; eval 'use RDF::vCard::Entity::WithXmlSupport;'; $WITH_XML = !$@; } sub new_entity { my ($class, @params) = @_; $class .= ($WITH_XML ? '::Entity::WithXmlSupport' : '::Entity'); return $class->new(@params); } 1; __END__ =head1 NAME RDF::vCard - convert between RDF and vCard =head1 SYNOPSIS use RDF::vCard; use RDF::TrineShortcuts qw(rdf_string); my $input = "http://example.com/contact-data.rdf"; my $exporter = RDF::vCard::Exporter->new; my $data = join '', $exporter->export_cards($input); print $data; # vCard 3.0 data my $importer = RDF::vCard::Importer->new; $importer->import_string($data); print rdf_string($importer->model => 'RDFXML'); =head1 DESCRIPTION This module doesn't do anything itself; it just loads RDF::vCard::Exporter and RDF::vCard::Importer for you. =head2 RDF::vCard::Exporter L takes some RDF using the W3C's vCard vocabulary, and outputs L objects. =head2 RDF::vCard::Importer L does the reverse. =head2 RDF::vCard::Entity An L objects is an individual vCard. It overloads stringification, so just treat it like a string. =head2 RDF::vCard::Entity::WithXmlSupport L is a subclass of L, with a C method. It requires L to be installed and working. The importer and exporter will try to create these if possible. =head2 RDF::vCard::Line L is internal fu that you probably don't want to touch. =head1 BUGS If your RDF asserts that Alice is Bob's AGENT and Bob is Alice's AGENT, then L will eat your face. Don't do it. Please report any other bugs to L. =head1 SEE ALSO L. L. L. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT Copyright 2011 Toby Inkster This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Entity.pm000664001750001750 1670312406373420 16045 0ustar00taitai000000000000RDF-vCard-0.012/lib/RDF/vCardpackage RDF::vCard::Entity; use 5.008; use strict; use warnings; no warnings qw(uninitialized); use JSON qw[]; use RDF::TrineX::Functions -shortcuts, statement => { -as => 'rdf_statement' }, iri => { -as => 'rdf_resource' }; sub V { return 'http://www.w3.org/2006/vcard/ns#' . shift; } sub VX { return 'http://buzzword.org.uk/rdf/vcardx#' . shift; } sub RDF { return 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' . shift; } sub XSD { return 'http://www.w3.org/2001/XMLSchema#' . shift; } use namespace::clean; use overload '""' => \&to_string; our $VERSION = '0.012'; sub new { my ($class, %options) = @_; $options{profile} ||= 'VCARD'; $options{lines} ||= []; $options{components} ||= []; $options{node} ||= $class->_node; bless { %options }, $class; } sub _node { my ($class) = @_; return RDF::Trine::Node::Blank->new; } sub profile { my ($self) = @_; return $self->{profile}; } sub lines { my ($self) = @_; return $self->{lines}; } sub components { my ($self) = @_; return $self->{components}; } sub add { my ($self, $line) = @_; push @{ $self->lines }, $line; $self->_entity_order_fu($line); return $self; } sub add_component { my ($self, $c) = @_; push @{ $self->components }, $c; return $self; } sub get { my ($self, $property) = @_; return grep { lc $_->property eq lc $property } @{ $self->lines }; } sub matches { my ($self, $property, $regexp) = @_; return grep { $_->value_to_string =~ $regexp; } $self->get($property); } sub entity_order { my ($self) = @_; return $self->{property}{'sort-string'} || $self->{property}{'n'} || $self->{property}{'n-faked'} || $self->{property}{'fn'} || $self->{property}{'nickname'}; } sub _entity_order_fu { my ($self, $line) = @_; if ($line->property =~ /^(sort.string|n|fn|nickname)$/i) { my $x = $line->value_to_string; $self->{property}{ lc $line->property } = $x if length $x; if (lc $line->property eq 'fn') { my @parts = split /\s+/, $x; my $last = pop @parts; unshift @parts, $last; $self->{property}{'n-faked'} = join ';', @parts; } } return $self; } sub to_string { my ($self) = @_; my @lines = sort { $a->property_order cmp $b->property_order; } @{$self->lines}; my @components = sort { $a->entity_order cmp $b->entity_order; } @{$self->components}; my $str = sprintf("BEGIN:%s\r\n", $self->profile); foreach my $line (@lines) { $str .= $line . "\r\n"; } foreach my $component (@components) { $str .= $component; } $str .= sprintf("END:%s\r\n", $self->profile); return $str; } sub node { my ($self) = @_; return $self->{node}; } sub add_to_model { my ($self, $model) = @_; $model->add_statement(rdf_statement( $self->node, rdf_resource( RDF('type') ), rdf_resource( V('VCard') ), )); foreach my $line (@{ $self->lines }) { $line->add_to_model($model, $self->node); } return $self; } sub to_jcard { my ($self, $hashref) = @_; return ($hashref ? $self->TO_JSON : JSON::to_json($self)); } { my @singular = qw(fn n bday tz geo sort-string uid class rev anniversary birth dday death gender kind prodid sex version); my @typed = qw(email tel adr label impp); sub TO_JSON { my ($self) = @_; my $object = {}; foreach my $line (@{ $self->lines }) { my $p = lc $line->property; if ($p eq 'n') { my $o; my @sp = qw(family-name given-name additional-name honorific-prefix honorific-suffix); for my $i (0..4) { if ($line->nvalue->[$i] and @{$line->nvalue->[$i]}) { $o->{ $sp[$i] } = [ @{$line->nvalue->[$i]} ]; } } push @{$object->{n}}, $o; } elsif ($p eq 'org') { my @components = map { $_->[0] } @{$line->nvalue}; my $o = { 'organization-name' => shift @components }; $o->{'organization-unit'} = \@components; push @{$object->{n}}, $o; } elsif ($p eq 'adr') { my $o; while (my ($k, $v) = each %{$line->type_parameters}) { push @{$o->{$k}}, (ref $v eq 'ARRAY' ? @$v : $v); } if ($o->{type}) { $o->{type} = [ sort map {lc $_} @{ $o->{type} } ] } my @sp = qw(post-office-box extended-address street-address locality region country-name postal-code); for my $i (0..6) { if ($line->nvalue->[$i] and @{$line->nvalue->[$i]}) { $o->{ $sp[$i] } = [ @{$line->nvalue->[$i]} ]; } } push @{$object->{adr}}, $o; } elsif ($p eq 'categories') { push @{$object->{categories}}, '@@TODO'; } elsif ($p eq 'geo') { $object->{geo} = { latitude => $line->nvalue->[0][0], longitude => $line->nvalue->[1][0], }; } elsif (grep { $_ eq $p } @typed) { my $o = {}; while (my ($k, $v) = each %{$line->type_parameters}) { push @{$o->{$k}}, (ref $v eq 'ARRAY' ? @$v : $v); } $o->{value} = $line->nvalue->[0][0]; if ($o->{type}) { $o->{type} = [ sort map {lc $_} @{ $o->{type} } ] } push @{ $object->{$p} }, $o; } elsif (grep { $_ eq $p } @singular) { $object->{$p} ||= $line->nvalue->[0][0]; } else { push @{ $object->{$p} }, $line->nvalue->[0][0]; } } return $object; } } 1; __END__ =head1 NAME RDF::vCard::Entity - represents a single vCard =head1 DESCRIPTION Instances of this class correspond to individual vCard objects, though it could potentially be used as basis for other RFC 2425-based formats such as iCalendar. =head2 Constructor =over =item * C<< new(%options) >> Returns a new RDF::vCard::Entity object. The only option worth worrying about is B which sets the profile for the entity. This defaults to "VCARD". RDF::vCard::Entity overloads stringification, so you can do the following: my $vcard = RDF::vCard::Entity->new; print $vcard if $vcard =~ /VCARD/i; =back =head2 Methods =over =item * C<< to_string() >> Formats the object according to RFC 2425 and RFC 2426. =item * C<< to_jcard() >> Formats the object according to L. C<< to_jcard(1) >> will return the same data but without the JSON stringification. =item * C<< add_to_model($model) >> Given an RDF::Trine::Model, adds triples to the model for this entity. =item * C<< node() >> Returns an RDF::Trine::Node::Blank identifying this entity. =item * C<< entity_order() >> Returns a string along the lines of "Surname;Forename" useful for sorting a list of entities. =item * C<< profile() >> Returns the entity type - e.g. "VCARD". =item * C<< lines() >> Returns an arrayref of L objects in the order they were originally added. This excludes the "BEGIN:VCARD" and "END:VCARD" lines. =item * C<< add($line) >> Add a L. =item * C<< get($property) >> Returns a list of L objects for the given property. e.g. print "It has an address!\n" if ($vcard->get('ADR')); =item * C<< matches($property, $regexp) >> Checks to see if a property's value matches a regular expression. print "In London\n" if $vcard->matches(ADR => /London/); =item * C<< add_component($thing) >> Adds a nested entity within this one. This method is unused for vCard, but is a hook for the benefit of L. =item * C<< components >> Lists nested entities within this one. =back =begin private =item TO_JSON =end private =head1 SEE ALSO L. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT Copyright 2011 Toby Inkster This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Exporter.pm000664001750001750 4357612406373420 16411 0ustar00taitai000000000000RDF-vCard-0.012/lib/RDF/vCardpackage RDF::vCard::Exporter; use 5.008; use strict; use warnings; no warnings qw(uninitialized); use MIME::Base64 qw[]; use RDF::vCard::Entity; use RDF::vCard::Line; use RDF::TrineX::Functions -shortcuts, iri => { -as => 'rdf_resource' }; use Scalar::Util qw[blessed]; use URI; # kinda constants sub V { return 'http://www.w3.org/2006/vcard/ns#' . shift; } sub VX { return 'http://buzzword.org.uk/rdf/vcardx#' . shift; } sub RDF { return 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' . shift; } sub XSD { return 'http://www.w3.org/2001/XMLSchema#' . shift; } sub flatten_node { my $node = shift; return $node->value if $node->is_resource || $node->is_literal; return $node->as_ntriples; } use namespace::clean; our $VERSION = '0.012'; our $PRODID = sprintf("+//IDN cpan.org//NONSGML %s v %s//EN", __PACKAGE__, $VERSION); our %dispatch = ( V('adr') => \&_prop_export_adr, V('n') => \&_prop_export_n, V('geo') => \&_prop_export_geo, V('org') => \&_prop_export_org, V('agent') => \&_prop_export_agent, V('tel') => \&_prop_export_typed, V('email') => \&_prop_export_typed, V('label') => \&_prop_export_typed, VX('impp') => \&_prop_export_typed, V('fax') => \&_prop_export_shortcut, V('homeAdr') => \&_prop_export_shortcut, V('homeTel') => \&_prop_export_shortcut, V('mobileEmail') => \&_prop_export_shortcut, V('mobileTel') => \&_prop_export_shortcut, V('personalEmail') => \&_prop_export_shortcut, V('unlabeledAdr') => \&_prop_export_shortcut, V('unlabeledEmail') => \&_prop_export_shortcut, V('unlabeledTel') => \&_prop_export_shortcut, V('workAdr') => \&_prop_export_shortcut, V('workEmail') => \&_prop_export_shortcut, V('workTel') => \&_prop_export_shortcut, V('photo') => \&_prop_export_binary, V('sound') => \&_prop_export_binary, V('logo') => \&_prop_export_binary, V('key') => \&_prop_export_binary, ); sub new { my ($class, %options) = @_; bless { %options }, $class; } sub is_v4 { my ($self) = @_; return ($self->{vcard_version} =~ /4/) ? 4 : 0; } sub is_v3 { my ($self) = @_; return $self->is_v4 ? 0 : 3; } sub export_cards { my ($self, $model, %options) = @_; $model = rdf_parse($model) unless blessed($model) && $model->isa('RDF::Trine::Model'); my @subjects = $model->subjects(rdf_resource(RDF('type')), rdf_resource(V('VCard'))); push @subjects, $model->subjects(rdf_resource(V('fn')), undef); my %subjects = map { flatten_node($_) => $_ } @subjects; my @cards; foreach my $s (values %subjects) { push @cards, $self->export_card($model, $s, %options); } if ($options{sort}) { return sort { $a->entity_order cmp $b->entity_order } @cards; } return @cards; } sub export_card { my ($self, $model, $subject, %options) = @_; $model = RDF::TrineShortcuts::rdf_parse($model) unless blessed($model) && $model->isa('RDF::Trine::Model'); my $card = RDF::vCard->new_entity( profile=>'VCARD' ); my %categories; my $triples = $model->get_statements($subject, undef, undef); while (my $triple = $triples->next) { next unless (substr($triple->predicate->uri, 0, length(&V)) eq &V or substr($triple->predicate->uri, 0, length(&VX)) eq &VX); if (defined $dispatch{$triple->predicate->uri} and ref($dispatch{$triple->predicate->uri}) eq 'CODE') { my $code = $dispatch{$triple->predicate->uri}; $card->add($code->($self, $model, $triple)); } elsif ($triple->predicate->uri eq V('category') or $triple->predicate->uri eq VX('category')) { my $c = $self->_prop_extract_category($model, $triple); $categories{$c}++; } elsif (! $triple->object->is_blank) { $card->add($self->_prop_export_simple($model, $triple)); } } if (keys %categories) { $card->add( RDF::vCard::Line->new( property => 'categories', value => [[ sort keys %categories ]], ) ); } $card->add( RDF::vCard::Line->new( property => 'version', value => $self->is_v4 ? '4.0' : '3.0', ) ); $card->add( RDF::vCard::Line->new( property => 'prodid', value => (defined $options{prodid} ? $options{prodid} : $PRODID), ) ) unless exists $options{prodid} && !defined $options{prodid}; $card->add( RDF::vCard::Line->new( property => 'source', value => $options{source}, type_parameters => {value=>'URI'}, ) ) if defined $options{source}; return $card; } { my %dtmap = ( XSD('anyURI') => 'URI', XSD('string') => 'TEXT', XSD('integer') => 'INTEGER', XSD('date') => 'DATE', XSD('dateTime') => 'DATE-TIME', XSD('duration') => 'DURATION', 'urn:iso:std:iso:8601#timeInterval' => 'PERIOD', XSD('decimal') => 'FLOAT', # BOOLEAN ? ); sub _prop_export_simple { my ($self, $model, $triple) = @_; my $prop = 'x-data'; if ($triple->predicate->uri =~ m/([^\#\/]+)$/) { $prop = $1; } my $val = flatten_node($triple->object); my $params = undef; if ($triple->object->is_literal and $triple->object->has_datatype and defined $dtmap{ $triple->object->literal_datatype }) { $params = { value => $dtmap{ $triple->object->literal_datatype } }; } elsif ($triple->object->is_literal and $triple->object->has_language) { $params = { value=>'TEXT', language=>$triple->object->literal_value_language }; } elsif ($triple->object->is_resource) { $params = { value=>'URI' }; } return RDF::vCard::Line->new( property => $prop, value => $val, type_parameters => $params, ); } } sub _prop_export_adr { my ($self, $model, $triple) = @_; my $adr = []; foreach my $part (qw(post-office-box extended-address street-address locality region postal-code country-name)) { my @objects = $model->objects($triple->object, rdf_resource(V($part))); push @$adr, [ map { flatten_node($_) } @objects ]; } my $params = {}; my $types = {}; unless ($triple->object->is_literal) { my @types = $model->objects($triple->object, rdf_resource(RDF('type'))); push @types, $model->objects($triple->object, rdf_resource(VX('usage'))); foreach my $type (@types) { if ($type->is_resource and $type->uri =~ m/([^\#\/]+)$/) { $types->{ uc $1 } = 1; } elsif ($type->is_literal) { $types->{ uc $type->literal_value } = 1; } } } delete $types->{TEL}; delete $types->{EMAIL}; delete $types->{IMPP}; delete $types->{ADDRESS}; delete $types->{LABEL}; my @geos; my $iter = $model->get_statements($triple->object, rdf_resource(VX('geo')), undef); while (my $st = $iter->next) { my $gline = $self->_prop_export_geo($model, $st); push @geos, $gline->_unescape_value($gline->value_to_string); } if (@geos) { $params->{geo} = \@geos; } if (%$types and $self->is_v4) { $params->{type} = [sort grep { !/^pref$/i } keys %$types]; $params->{pref} = 1 if $types->{PREF}; } elsif (%$types) { $params->{type} = [sort keys %$types]; } $params = undef unless %$params; return RDF::vCard::Line->new( property => 'adr', value => $adr, type_parameters => $params, ); } sub _prop_export_n { my ($self, $model, $triple) = @_; my $n = []; foreach my $part (qw(family-name given-name additional-name honorific-prefix honorific-suffix)) { my @objects = $model->objects($triple->object, rdf_resource(V($part))); push @$n, [ map { flatten_node($_) } @objects ]; } return RDF::vCard::Line->new( property => 'n', value => $n, ); } sub _prop_export_agent { my ($self, $model, $triple) = @_; if ($triple->object->is_literal) { return RDF::vCard::Line->new( property => 'agent', value => flatten_node($triple->object), type_parameters => { value=>'TEXT' }, ); } my $agent = $self->export_card($model, $triple->object); return RDF::vCard::Line->new( property => 'agent', value => $agent->to_string, type_parameters => { value=>'VCARD' }, ); } sub _prop_export_org { my ($self, $model, $triple) = @_; # Note: W3C Member Submission is inconsistent with regards to organiSation/organiZation. my @objects = $model->objects_for_predicate_list($triple->object, rdf_resource(V('organization-name')), rdf_resource(V('organisation-name'))); my @values = map { flatten_node($_) } grep {$_->is_literal} @objects; my $org = [ ($values[0] || '') ]; @objects = $model->objects_for_predicate_list($triple->object, rdf_resource(V('organization-unit')), rdf_resource(V('organisation-unit'))); push @$org, map { flatten_node($_) } grep {$_->is_literal} @objects; return RDF::vCard::Line->new( property => 'org', value => $org, ); } sub _prop_export_geo { my ($self, $model, $triple) = @_; my $g = []; foreach my $part (qw(latitude longitude)) { my @objects = $model->objects($triple->object, rdf_resource(V($part))); my @values = map { flatten_node($_) } grep {$_->is_literal} @objects; push @$g, ($values[0] || ''); } if ($self->is_v4) { return RDF::vCard::Line->new( property => 'geo', value => sprintf('geo:%f,%f', @$g), type_parameters => { value=>'URI' }, ); } else { return RDF::vCard::Line->new( property => 'geo', value => $g, type_parameters => { value=>'TEXT' }, ); } } # tel, email, label and impp may be typed sub _prop_export_typed { my ($self, $model, $triple) = @_; my $value_node = $triple->object; unless ($value_node->is_literal) { my @objects = $model->objects($value_node, rdf_resource(RDF('value'))); foreach my $o (@objects) { unless ($o->is_blank) { $value_node = $o; last; } } } my $value = flatten_node($value_node); my $prop = 'x-data'; if ($triple->predicate->uri =~ m/([^\#\/]+)$/) { $prop = lc $1; } my $types = {}; my $params = {}; if ($prop eq 'email' and $value =~ /^mailto:(.+)$/i) { $value = $1; $types->{INTERNET} = 1; } elsif ($prop eq 'tel' and $value =~ /^(tel|fax|modem):(.+)$/i) { if ($self->is_v4) #v4 telephone numbers are URIs { $params = { value=>'URI' }; } else #v3 telephone numbers are text (well VALUE=PHONE-NUMBER technically) { $value = $2; } $types->{FAX} = 1 if lc $1 eq 'fax'; $types->{MODEM} = 1 if lc $1 eq 'modem'; } elsif ($value_node->is_resource) { $params = { value=>'URI' }; } unless ($triple->object->is_literal) { my @types = $model->objects($triple->object, rdf_resource(RDF('type'))); push @types, $model->objects($triple->object, rdf_resource(VX('usage'))); foreach my $type (@types) { if ($type->is_resource and $type->uri =~ m/([^\#\/]+)$/) { $types->{ uc $1 } = 1; } elsif ($type->is_literal) { $types->{ uc $type->literal_value } = 1; } } } delete $types->{TEL}; delete $types->{EMAIL}; delete $types->{IMPP}; delete $types->{ADDRESS}; delete $types->{LABEL}; if (%$types and $self->is_v4) { $params->{type} = [sort grep { !/^pref$/i } keys %$types]; $params->{pref} = 1 if $types->{PREF}; } elsif (%$types) { $params->{type} = [sort keys %$types]; } $params = undef unless %$params; if ($prop eq 'tel') { $params->{'value'} ||= 'PHONE-NUMBER'; if ($self->is_v4 and $params->{'value'} ne 'URI' and $value =~ /^\+[0-9\s\-]+$/) { $value =~ s/\s/-/g; $value = "tel:${value}"; $params->{'value'} = 'URI'; } } return RDF::vCard::Line->new( property => $prop, value => $value, type_parameters => $params, ); } sub _prop_export_shortcut { my ($self, $model, $triple) = @_; my $shortcuts = { V('fax') => [V('tel') => ['FAX']], V('homeAdr') => [V('adr') => ['HOME']], V('homeTel') => [V('tel') => ['HOME']], V('mobileEmail') => [V('email') => undef], # EMAIL;TYPE=CELL not allowed by RFC 2426 V('mobileTel') => [V('tel') => ['CELL']], V('personalEmail') => [V('email') => undef], # RFC 2426 doesn't define TYPE=PERSONAL V('unlabeledAdr') => [V('adr') => undef], V('unlabeledEmail') => [V('email') => undef], V('unlabeledTel') => [V('tel') => undef], V('workAdr') => [V('adr') => ['WORK']], V('workEmail') => [V('email') => undef], # EMAIL;TYPE=WORK not allowed by RFC 2426 V('workTel') => [V('tel') => ['WORK']], }; if (exists $shortcuts->{$triple->predicate->uri}) { my ($property_uri, $types) = @{ $shortcuts->{$triple->predicate->uri} }; my $line; if (defined $dispatch{$property_uri} and ref($dispatch{$property_uri}) eq 'CODE') { my $code = $dispatch{$property_uri}; $line = $code->($self, $model, $triple); } elsif (! $triple->object->is_blank) { $line = $self->_prop_export_simple($model, $triple); } if ($line) { push @{ $line->type_parameters->{type} }, @$types; return $line; } } } sub _prop_export_binary { my ($self, $model, $triple) = @_; my $line = $self->_prop_export_simple($model, $triple); if ($self->is_v3 and $line->value->[0] =~ /^data:\S+$/) { my $data_uri = URI->new( $line->value->[0] ); my $data = $data_uri->data; my $medium = $data_uri->media_type; $line->value->[0] = MIME::Base64::encode_base64($data, ''); $line->type_parameters->{value} = 'BINARY'; $line->type_parameters->{encoding} = 'B'; $line->type_parameters->{type} = [ uc($1) ] if $medium =~ m'^image/([a-z0-9\_\-\+]+)'i; $line->type_parameters->{fmtype} = $medium if $medium =~ m'.+/.+'; } return $line; } sub _prop_extract_category { my ($self, $model, $triple) = @_; if ($triple->object->is_literal) { return uc $triple->object->literal_value; } my @labels = grep { $_->is_literal } $model->objects_for_predicate_list( $triple->object, rdf_resource('http://www.w3.org/2004/02/skos/core#prefLabel'), rdf_resource('http://www.holygoat.co.uk/owl/redwood/0.1/tags/name'), rdf_resource('http://www.w3.org/2000/01/rdf-schema#label'), rdf_resource('http://www.w3.org/2004/02/skos/core#altLabel'), rdf_resource('http://www.w3.org/2004/02/skos/core#notation'), rdf_resource(RDF('value')), ); if (@labels) { return uc $labels[0]->literal_value; } elsif ($triple->object->is_resource) { return $triple->object->uri; } } 1; __END__ =head1 NAME RDF::vCard::Exporter - export RDF data to vCard format =head1 SYNOPSIS use RDF::vCard; my $input = "http://example.com/contact-data.rdf"; my $exporter = RDF::vCard::Exporter->new(vcard_version => 3); print $_ foreach $exporter->export_cards($input); =head1 DESCRIPTION This module reads RDF and writes vCards. =head2 Constructor =over =item * C<< new(%options) >> Returns a new RDF::vCard::Exporter object. Options: =over =item * B - '3' or '4'. This module will happily use vCard 3.0 constructs in vCard 4.0 and vice versa. But in certain places it can lean one way or the other. This option allows you to influence that. =back =back =head2 Methods =over =item * C<< export_cards($input, %options) >> Returns a list of vCards found in the input, in no particular order. The input may be a URI, file name, L or anything else that can be handled by the C method of L. Supported options include B which, if set to true, causes the output to be sorted by name (as well as is possible); B which allows you to provide the URL where the cards were sourced from; and B which allows you to set the product ID used in the output. (A prodid must be in FPI format to be valid, though the module doesn't check this. undef is allowed. By default, RDF::vCard:Exporter uses its own prodid, and unless you have a good reason to change this, you should probably let it.) e.g. my @cards = $exporter->export_cards( $some_data, sort => 1, source => 'http://bigcorp.example.com/data.rdf', prodid => '+//IDN example.net//NONSGML MyScript v 0.1//EN', ); Each item in the list returned is an L, though that class overloads stringification, so you can just treat each item as a string mostly. =item * C<< export_card($input, $subject, %options) >> As per C but exports just a single card. The subject provided must be an RDF::Trine::Node::Blank or RDF::Trine::Node::Resource of type v:VCard. =item * C<< is_v3 >> Returns true if this exporter is in vCard 3.0 mode. =item * C<< is_v4 >> Returns true if this exporter is in vCard 4.0 mode. =back =head2 RDF Input Input is expected to use the newer of the 2010 revision of the W3C's vCard vocabulary L. (Note that even though this was revised in 2010, the term URIs include "2006" in them.) Some extensions from the namespace L are also supported. (Namely: vx:usage, vx:kind, vx:gender, vx:sex, vx:dday, vx:anniversary, vx:lang, vx:caladruri, vx:caluri, vx:fburl, vx:impp, vx:source.) The module author has made the decision not to support FOAF and other RDF vocabularies that may be used to model contact information for people and organisations, as they do not necessarily map cleanly onto vCard. People hoping to map non-vCard RDF to vCard using this module may have some luck pre-processing their RDF using a rules-based reasoner. =head2 vCard Output The output of this module mostly aims at vCard 3.0 (RFC 2426) compliance. In the face of weird input data though, (e.g. an FN property that is a URI instead of a literal) it can pretty easily descend into exporting junk, non-compliant vCards. Many vCard 4.0 properties, such as the IMPP and KIND, are also supported. The B constructor option allows you to influence how some properties like GEO and TEL (which differ between 3.0 and 4.0) are output. =head1 SEE ALSO L, L, L. L. L. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT Copyright 2011 Toby Inkster This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Importer.pm000664001750001750 1522012406373420 16363 0ustar00taitai000000000000RDF-vCard-0.012/lib/RDF/vCardpackage RDF::vCard::Importer; use 5.008; use strict; use warnings; no warnings qw(uninitialized); use Encode qw[]; use RDF::TrineX::Functions -shortcuts; use RDF::vCard::Entity; use RDF::vCard::Line; use Text::vFile::asData; use namespace::clean; our $VERSION = '0.012'; sub new { my ($class, %options) = @_; my $self = bless { %options }, $class; $self->init unless $self->model; return $self; } sub init { my ($self, $model, %opts) = @_; $self->{model} = rdf_parse($model, %opts); return $self; } sub model { my ($self) = @_; return $self->{model}; } *TO_RDF = \&model; sub _ua { my ($self) = @_; $self->{ua} ||= LWP::UserAgent->new(agent => sprintf('%s/%s', __PACKAGE__, $VERSION)); return $self->{ua}; } sub import_file { my ($self, $file, %options) = @_; open my $fh, "<:encoding(UTF-8)", $file; my $cards = Text::vFile::asData->new->parse($fh); close $fh; return $self->_process($cards, %options); } sub import_fh { my ($self, $fh, %options) = @_; my $cards = Text::vFile::asData->new->parse($fh); return $self->_process($cards, %options); } sub import_url { my ($self, $url) = @_; my $r = $self->_ua->get($url, Accept=>'text/directory;profile=vCard, text/vcard, text/x-vcard, text/directory;q=0.1'); return unless $r->is_success; return $self->import_string($r->decoded_content, lang => $r->content_language); } sub import_string { my ($self, $data, %options) = @_; my @lines = split /\r?\n/, $data; my $cards = Text::vFile::asData->new->parse_lines(@lines); return $self->_process($cards, %options); } sub _process { my ($self, $cards, %options) = @_; my @Cards; foreach my $c (@{ $cards->{objects} }) { push @Cards, $self->_process_card($c, %options); } return @Cards; } sub _process_card { my ($self, $card, %options) = @_; my $C = RDF::vCard->new_entity( profile => $card->{type} ); while (my ($prop, $vals) = each %{ $card->{properties} }) { my $group; if ($prop =~ /^(.+)\.([^\.]+)$/) # ignore vCard 4.0 grouping construct { $prop = $2; $group = $1; } foreach my $val (@$vals) { my $strval = $val->{value}; # I wish Text::vFile::asData did this for me! my $structured_value = ($prop =~ /^(ADR|CATEGORIES|GEO|N|ORG)$/i) ? $self->_extract_structure($strval) : RDF::vCard::Line->_unescape_value($strval); # Could technically extract structure for all properties, # but it's a waste of time, and some of the RDF::vCard::Line # code might cope badly. my $L = RDF::vCard::Line->new( property => uc $prop, value => $structured_value, type_parameters => do { # force keys to uppercase my (%tp, $k, $v); $tp{uc $k} = $v while ($k, $v) = each %{$val->{param}}; \%tp; }, ); $L->type_parameters->{TYPE} = [split /,/, $L->type_parameters->{TYPE}] if ($L->type_parameters and $L->type_parameters->{TYPE}); $L->type_parameters->{_GROUP} = $group if $group; $L->type_parameters->{LANG} ||= $options{lang} if defined $options{lang}; $C->add($L); } } $C->add_to_model( $self->model ); return $C; } sub _extract_structure { my ($self, $string) = @_; my @naive_parts = split /;/, $string; my @parts; while (my $part = shift @naive_parts) { push @parts, $part; while ($parts[-1] =~ /\\$/ and $parts[-1] !~ /\\\\$/ and @naive_parts) { $parts[-1] =~ s/\\$/;/; $parts[-1] .= shift @naive_parts; } } my @rv; foreach my $part (@parts) { my @naive_subparts = split /,/, $part; my @subparts; while (my $subpart = shift @naive_subparts) { push @subparts, $subpart; while ($subparts[-1] =~ /\\$/ and $subparts[-1] !~ /\\\\$/ and @naive_subparts) { $subparts[-1] =~ s/\\$/,/; $subparts[-1] .= shift @naive_subparts; } } push @rv, [ map { RDF::vCard::Line->_unescape_value($_) } @subparts ]; } return [@rv]; } 1; __END__ =head1 NAME RDF::vCard::Importer - import RDF data from vCard format =head1 SYNOPSIS use RDF::vCard; use RDF::TrineShortcuts qw':all'; my $importer = RDF::vCard::Importer->new; print $_ foreach $importer->import_file('contacts.vcf'); print rdf_string($importer->model => 'RDFXML'); =head1 DESCRIPTION This module reads vCards and writes RDF. =head2 Constructor =over =item * C<< new(%options) >> Returns a new RDF::vCard::Importer object and initialises it. The only valid option currently is B which can be set to an LWP::UserAgent for those rare occasions that the Importer needs to fetch stuff from the Web. =back =head2 Methods =over =item * C<< init >> Reinitialise the importer. Forgets any cards that have already been imported. =item * C<< model >> Return an RDF::Trine::Model containing data for all cards that have been imported since the importer was last initialised. =item * C<< import_file($filename, %options) >> Imports vCard data from a file on the file system. The data is added to the importer's model (and can be retrieved using the C method). This function returns a list of L objects, so it's also possible to access the data that way. There is currently only one supported option: C which takes an ISO language code indicating the default language of text within the vCard data. =item * C<< import_fh($filehandle, %options) >> As per C, but operates on a file handle. =item * C<< import_string($string, %options) >> As per C, but operates on vCard data in a string. =item * C<< import_url($url) >> As per C, but fetches vCard data from a Web address. Sends an HTTP Accept header of: text/directory;profile=vCard, text/vcard, text/x-vcard, text/directory;q=0.1 =back =begin private =item TO_RDF =end private =head2 vCard Input vCard 3.0 should be supported fairly completely. Some vCard 4.0 constructs will also work. Much of the heavy lifting is performed by L, so this module may be affected by bugs in that distribution. =head2 RDF Output Output uses the newer of the 2010 revision of the W3C's vCard vocabulary L. (Note that even though this was revised in 2010, the term URIs include "2006" in them.) Some extensions from the namespace L are also output. The AGENT property is currently omitted from output. This will be added in a later version. =head1 SEE ALSO L. L. L. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT Copyright 2011 Toby Inkster This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Line.pm000664001750001750 3211112406373420 15447 0ustar00taitai000000000000RDF-vCard-0.012/lib/RDF/vCardpackage RDF::vCard::Line; use 5.008; use strict; use warnings; no warnings qw(uninitialized); use Encode; use MIME::Base64; use RDF::Trine::Namespace qw[xsd]; use RDF::TrineX::Functions -shortcuts, statement => { -as => 'rdf_statement' }, literal => { -as => 'rdf_literal' }, iri => { -as => 'rdf_resource' }; use URI::data; sub V { return 'http://www.w3.org/2006/vcard/ns#' . shift; } sub VX { return 'http://buzzword.org.uk/rdf/vcardx#' . shift; } sub RDF { return 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' . shift; } sub XSD { return 'http://www.w3.org/2001/XMLSchema#' . shift; } use namespace::clean; use overload '""' => \&to_string; our $VERSION = '0.012'; sub new { my ($class, %options) = @_; die "Need to provide a property name\n" unless defined $options{property}; $options{value} = [$options{value}] unless ref $options{value} eq 'ARRAY'; $options{type_parameters} ||= []; bless { %options }, $class; } sub property { my ($self) = @_; return $self->{property}; } sub value { my ($self) = @_; return $self->{value}; } sub nvalue { my ($self) = @_; my $value = $self->value; my @nvalue; foreach my $v (@$value) { push @nvalue, (ref($v) eq 'ARRAY' ? $v : [$v]); } return \@nvalue; } sub type_parameters { my ($self) = @_; $self->{type_parameters} = {} unless ref $self->{type_parameters} eq 'HASH'; return $self->{type_parameters}; } sub property_order { my ($self) = @_; my $p = lc $self->property; return 0 if $p eq 'version'; return 1 if $p eq 'prodid'; return 2 if $p eq 'source'; return 3 if $p eq 'kind'; return 4 if $p eq 'fn'; return 5 if $p eq 'n'; return 6 if $p eq 'org'; return $p; } sub to_string { my ($self) = @_; my $str = uc $self->property; if (keys %{ $self->type_parameters }) { foreach my $parameter (sort keys %{ $self->type_parameters }) { my $values = $self->type_parameters->{$parameter}; $values = [$values] unless ref $values eq 'ARRAY'; my $values_string = join ",", map { $self->_escape_value($_, is_tp=>1) } @$values; $str .= sprintf(";%s=%s", uc $parameter, $values_string); } } $str .= ":"; $str .= $self->value_to_string; if (length $str > 75) { my $new = ''; while (length $str > 64) { $new .= substr($str, 0, 64) . "\r\n "; $str = substr($str, 64); } $new .= $str; $str = $new; } return $str; } sub value_to_string { my ($self) = @_; my $str = join ";", map { join ",", map { $self->_escape_value($_) } @{$_}; } @{ $self->nvalue }; $str =~ s/;+$//; return $str; } sub _escape_value { my ($self, $value, %options) = @_; if ($options{is_tp} and $value =~ /[;:,"]/) { $value =~ s/\\/\\\\/g; $value =~ s/\"/\\\"/g; return sprintf('"%s"', $value); } $value =~ s/\\/\\\\/g; $value =~ s/\r//g; $value =~ s/\n/\\n/g; $value =~ s/;/\\;/g; $value =~ s/,/\\,/g; return $value; } sub _unescape_value { my ($self, $value, %options) = @_; $value =~ s/\\r//gi; $value =~ s/\\n/\n/gi; $value =~ s/\\;/;/g; $value =~ s/\\,/,/g; $value =~ s/\\\\/\\/g; return $value; } # RDF Export Stuff... sub add_to_model { my ($self, $model, $card_node) = @_; my $special_func = sprintf('_add_to_model_%s', uc $self->property); if ($self->can($special_func)) { $self->$special_func($model, $card_node); } elsif ($self->property_node) { $model->add_statement(rdf_statement( $card_node, $self->property_node, $self->value_node, )); } return $self; } sub value_node { my ($self) = @_; return rdf_literal($self->value_to_string, undef, $xsd->date) if (defined $self->type_parameters and uc $self->type_parameters->{VALUE} eq 'DATE'); return rdf_literal($self->value_to_string, undef, $xsd->dateTime) if (defined $self->type_parameters and uc $self->type_parameters->{VALUE} eq 'DATE-TIME'); return rdf_resource($self->value_to_string) if (defined $self->type_parameters and uc $self->type_parameters->{VALUE} eq 'URI'); if (defined $self->type_parameters and uc $self->type_parameters->{VALUE} eq 'BINARY' and uc $self->type_parameters->{ENCODING} eq 'B') { my $uri = URI->new('data:'); if (ref $self->type_parameters->{TYPE} eq 'ARRAY') { $uri->media_type(sprintf('image/%s', lc $self->type_parameters->{TYPE}->[0])); } elsif (ref $self->type_parameters->{TYPE}) { $uri->media_type(sprintf('image/%s', lc $self->type_parameters->{TYPE})); } else { $uri->media_type('application/octet-stream'); } $uri->data( decode_base64($self->value->[0]) ); return rdf_resource("$uri"); } if (defined $self->type_parameters->{LANG}) { return rdf_literal($self->value_to_string, $self->type_parameters->{LANG}); } return rdf_literal($self->value_to_string); } sub property_node { my ($self) = @_; return rdf_resource(V(lc $self->property)) if lc $self->property =~ /^(adr|agent|email|geo|key|logo| n|org|photo|sound|tel|url|bday|category|class|fn| label|mailer|nickname|note|prodid|rev|role|sort\-string| title|tz|uid)$/xi; return rdf_resource(VX(lc $self->property)) if lc $self->property =~ /^(kind|gender|sex|dday| anniversary|lang|member|caladruri|caluri|fburl| impp|source)$/xi; return rdf_resource(VX(lc $self->property)) if lc $self->property =~ /^x-/; return; } { my %usage_type = ( bbs => V('BBS'), car => V('Car'), cell => V('Cell'), dom => V('Dom'), fax => V('Fax'), home => V('Home'), internet => V('Internet'), intl => V('Intl'), isdn => V('ISDN'), modem => V('Modem'), msg => V('Msg'), pager => V('Pager'), parcel => V('Parcel'), pcs => V('PCS'), postal => V('Postal'), pref => V('Pref'), video => V('Video'), voice => V('Voice'), work => V('Work'), x400 => V('X400'), ); my %intrinsic_type = ( adr => V('Address'), email => V('Email'), impp => VX('Impp'), label => V('Label'), tel => V('Tel'), ); sub _add_to_model_typed_thing { my ($self, $model, $card_node) = @_; my $intermediate_node = RDF::Trine::Node::Blank->new; $model->add_statement(rdf_statement( $card_node, $self->property_node, $intermediate_node, )); $model->add_statement(rdf_statement( $intermediate_node, rdf_resource(RDF('type')), rdf_resource($intrinsic_type{ lc $self->property }), )) if $intrinsic_type{ lc $self->property }; $model->add_statement(rdf_statement( $intermediate_node, rdf_resource(RDF('value')), $self->value_node, )); if ($self->type_parameters) { foreach my $type (@{ $self->type_parameters->{TYPE} }) { if ($usage_type{lc $type}) { $model->add_statement(rdf_statement( $intermediate_node, rdf_resource(RDF('type')), rdf_resource($usage_type{lc $type}), )); } $model->add_statement(rdf_statement( $intermediate_node, rdf_resource(VX('usage')), rdf_literal($type), )); } } return $intermediate_node; # useful for _add_to_model_ADR } } *_add_to_model_TEL = \&_add_to_model_typed_thing; *_add_to_model_EMAIL = \&_add_to_model_typed_thing; *_add_to_model_LABEL = \&_add_to_model_typed_thing; *_add_to_model_IMPP = \&_add_to_model_typed_thing; sub _add_to_model_AGENT { warn "Outputting AGENT property to RDF not yet supported."; } sub _add_to_model_ADR { my ($self, $model, $card_node) = @_; my $intermediate_node = $self->_add_to_model_typed_thing($model, $card_node); my @properties = ( V('post-office-box'), V('extended-address'), V('street-address'), V('locality'), V('region'), V('postal-code'), V('country-name'), ); my @components = @{ $self->nvalue }; for (my $i=0; defined $properties[$i]; $i++) { next unless $components[$i] && @{ $components[$i] }; foreach my $v (@{ $components[$i] }) { $model->add_statement(rdf_statement( $intermediate_node, rdf_resource($properties[$i]), rdf_literal($v), )); } } return $intermediate_node; } sub _add_to_model_GEO { my ($self, $model, $card_node) = @_; my $intermediate_node = RDF::Trine::Node::Blank->new; my @properties = ( V('latitude'), V('longitude'), ); $model->add_statement(rdf_statement( $card_node, $self->property_node, $intermediate_node, )); $model->add_statement(rdf_statement( $intermediate_node, rdf_resource(RDF('type')), rdf_resource(V('Location')), )); my @components = @{ $self->nvalue }; for (my $i=0; defined $properties[$i]; $i++) { next unless $components[$i] && @{ $components[$i] }; foreach my $v (@{ $components[$i] }) { $model->add_statement(rdf_statement( $intermediate_node, rdf_resource($properties[$i]), rdf_literal($v), )); } } return $intermediate_node; } sub _add_to_model_N { my ($self, $model, $card_node) = @_; my $intermediate_node = RDF::Trine::Node::Blank->new; my @properties = ( V('family-name'), V('given-name'), V('additional-name'), V('honorific-suffix'), V('honorific-prefix'), ); $model->add_statement(rdf_statement( $card_node, $self->property_node, $intermediate_node, )); $model->add_statement(rdf_statement( $intermediate_node, rdf_resource(RDF('type')), rdf_resource(V('Name')), )); my @components = @{ $self->nvalue }; for (my $i=0; defined $properties[$i]; $i++) { next unless $components[$i] && @{ $components[$i] }; foreach my $v (@{ $components[$i] }) { $model->add_statement(rdf_statement( $intermediate_node, rdf_resource($properties[$i]), rdf_literal($v), )); } } return $intermediate_node; } sub _add_to_model_ORG { my ($self, $model, $card_node) = @_; my @units; foreach my $v1 (@{ $self->nvalue }) { push @units, @$v1; } my $intermediate_node = RDF::Trine::Node::Blank->new; $model->add_statement(rdf_statement( $card_node, $self->property_node, $intermediate_node, )); $model->add_statement(rdf_statement( $intermediate_node, rdf_resource(RDF('type')), rdf_resource(V('Organization')), )); my $org = shift @units; if ($org) { $model->add_statement(rdf_statement( $intermediate_node, rdf_resource(V('organization-name')), rdf_literal($org), )); } foreach my $u (@units) { $model->add_statement(rdf_statement( $intermediate_node, rdf_resource(V('organization-unit')), rdf_literal($u), )); } } 1; __END__ =head1 NAME RDF::vCard::Line - represents a line within a vCard =head1 DESCRIPTION Instances of this class correspond to lines within vCards, though they could potentially be used as basis for other RFC 2425-based formats such as iCalendar. =head2 Constructor =over =item * C<< new(%options) >> Returns a new RDF::vCard::Line object. The only options worth worrying about are: B (case-insensitive property name), B (arrayref or single string value), B (hashref of property-related parameters). RDF::vCard::Entity overloads stringification, so you can do the following: my $line = RDF::vCard::Line->new( property => 'email', value => 'joe@example.net', type_parameters => { type=>['PREF','INTERNET'] }, ); print "$line\n" if $line =~ /internet/i; =back =head2 Methods =over =item * C<< to_string() >> Formats the line according to RFC 2425 and RFC 2426. =item * C<< add_to_model($model, $node) >> Given an RDF::Trine::Model and an RDF::Trine::Node representing the entity (i.e. vcard) that this line belongs to, adds triples to the model for this line. =item * C<< property() >> Returns the line's property - e.g. "EMAIL". =item * C<< property_node() >> Returns the line's property as an RDF::Trine::Node that can be used as an RDF predicate. Returns undef if a sensible URI cannot be found. =item * C<< property_order() >> Returns a string which can be used to sort a list of lines into a sensible order. =item * C<< value() >> Returns an arrayref for the value. Each item in the arrayref could be a plain scalar, or an arrayref of scalars. For example the arrayref representing this name: N:Smith;John;Edward,James which is the vCard representation of somebody with surname Smith, given name John and additional names (middle names) Edward and James, might be represented with the following "value" arrayref: [ 'Smith', 'John', ['Edward', 'James'], ] or maybe: [ ['Smith'], 'John', ['Edward', 'James'], ] That's why it's sometimes useful to have a normalised version of it... =item * C<< nvalue() >> Returns a normalised version of the arrayref for the value. It will always be an arrayref of arrayrefs. For example: [ ['Smith'], ['John'], ['Edward', 'James'], ] =item * C<< value_node() >> Returns the line's value as an RDF::Trine::Node that can be used as an RDF object. For some complex properties (e.g. ADR, GEO, ORG, N, etc) the result is not especially useful. =item * C<< value_to_string() >> Formats the line value according to RFC 2425 and RFC 2426. =item * C<< type_parameters() >> Returns the type_parameters hashref. Here be monsters (kinda). =back =head1 SEE ALSO L. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT Copyright 2011 Toby Inkster This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. WithXmlSupport.pm000664001750001750 1005212406373420 21025 0ustar00taitai000000000000RDF-vCard-0.012/lib/RDF/vCard/Entitypackage RDF::vCard::Entity::WithXmlSupport; use 5.008; use strict; use warnings; no warnings qw(uninitialized); use constant NS => 'urn:ietf:params:xml:ns:vcard-4.0'; use Scalar::Util qw[blessed]; use XML::LibXML; use base qw'RDF::vCard::Entity'; use namespace::clean; our $VERSION = '0.012'; sub promote { my ($class, $self) = @_; die "Cannot promote non-RDF::vCard::Entity object!\n" unless blessed($self) && $self->isa('RDF::vCard::Entity'); warn ("RDF::vCard::XML::Entity may not work property when used with %s input.", ref($self)) unless ref($self) eq 'RDF::vCard::Entity' || ref($self) eq 'RDF::vCard::XML::Entity'; return bless $self, $class; } sub to_xml { my ($self) = @_; my $document = XML::LibXML->new->parse_string(sprintf('', NS)); $self->add_to_document($document); return $document->toString; } sub add_to_document { my ($self, $document) = @_; my $root = $document->documentElement->addNewChild(NS, 'vcard'); my @sorted = sort { $a->property_order cmp $b->property_order } @{ $self->{lines} }; foreach my $l (@sorted) { next if $l->property =~ /^(version|prodid)$/i; $self->_add_line_to_node($l, $root); } return $root; } sub _add_line_to_node { my ($self, $line, $node) = @_; my $prop_node = $node->addNewChild(NS, lc $line->property); my $method = sprintf('_add_value_to_node_%s', lc $line->property); $method = '_add_value_to_node_GENERIC' unless $self->can($method); $self->$method($line, $prop_node); return $prop_node; } sub _add_value_to_node_GENERIC { my ($self, $line, $node) = @_; my $type = lc $line->type_parameters->{value} || 'text'; my $val_node = $node->addNewChild(NS, $type); $val_node->appendText($line->_unescape_value($line->value_to_string)); my %params = %{ $line->type_parameters }; delete $params{value}; if (%params) { my $params_node = $node->addNewChild(NS, 'parameters'); while (my ($p,$v) = each %params) { next unless length $p && defined $v; if (ref $v eq 'ARRAY') { foreach my $v2 (@$v) { $params_node->addNewChild(NS, lc $p)->appendText($v2||''); } } else { $params_node->addNewChild(NS, lc $p)->appendText($v||''); } } } return $val_node; } sub _add_value_to_node_n { my ($self, $line, $node) = @_; my @child_names = qw(surname given additional prefix suffix); my @components = @{ $line->nvalue }; for (my $i = 0; defined $child_names[$i]; $i++) { my $component_node = $node->addNewChild(NS, $child_names[$i]); foreach my $value (@{ $components[$i] }) { $component_node->addNewChild(NS, 'text')->appendText($value); } } return $node->childNodes; } sub _add_value_to_node_adr { my ($self, $line, $node) = @_; my @child_names = qw(pobox ext street locality region code country); my @components = @{ $line->nvalue }; for (my $i = 0; defined $child_names[$i]; $i++) { my $component_node = $node->addNewChild(NS, $child_names[$i]); foreach my $value (@{ $components[$i] }) { $component_node->addNewChild(NS, 'text')->appendText($value); } } return $node->childNodes; } 1; __END__ =head1 NAME RDF::vCard::Entity::WithXmlSupport - subclass of RDF::vCard::Entity =head1 DESCRIPTION Subclass of L with XML output support. Requires L. =head2 Constructor =over =item * C<< new(%options) >> As per L. =item * C<< promote($entity) >> Clones an existing L, but adds XML support. =back =head2 Methods As per L, but also: =over =item * C<< to_xml() >> Formats the object according to the vCard XML Internet Draft. =item * C<< add_to_document($document) >> Given an L object, adds the vCard data to the document as a child of the root element. =back =head1 SEE ALSO L. L. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT Copyright 2011 Toby Inkster This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.