CONTRIBUTING000664001750001750 614612404152737 14361 0ustar00taitai000000000000RDF-Prefixes-0.005NAME 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 231512404152737 14014 0ustar00taitai000000000000RDF-Prefixes-0.005Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: RDF-Prefixes Upstream-Contact: TOBYINK and Toby Inkster Source: https://metacpan.org/release/RDF-Prefixes Files: Changes META.json META.yml dist.ini doap.ttl Copyright: Copyright 2014 Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: t/01basic.t t/02warnings.t t/03prefixes.t t/04utf8.t Copyright: Copyright 2012 Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: CONTRIBUTING INSTALL LICENSE examples/basic.pl Copyright: Unknown License: Unknown Files: COPYRIGHT CREDITS SIGNATURE Copyright: None License: public-domain Files: README lib/RDF/Prefixes.pm Copyright: Copyright 2010-2013 Toby Inkster. License: GPL-1.0+ or Artistic-1.0 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 15512404152734 13516 0ustar00taitai000000000000RDF-Prefixes-0.005Maintainer: - TOBYINK - Toby Inkster Thanks: - Saašha Metsärantala Changes000664001750001750 207212404152734 14011 0ustar00taitai000000000000RDF-Prefixes-0.005RDF-Prefixes ============ Created: 2010-09-04 Home page: Bug tracker: Maintainer: Toby Inkster 0.005 2014-09-10 [ Packaging ] - Switch to Dist::Inkt. 0.004 2013-07-02 - Updated: Copyright 2013. - Updated: Drop usage of smartmatch operator. 0.003 2012-05-31 [ Documentation ] - Fix typo. Saašha Metsärantala++ [ Packaging ] - Add test case covering utf8 support. - Add test case covering warning message. [ Other ] - Disallow other vocabularies squatting on 'xsd' prefix. Saašha Metsärantala++ - Remove some redundant regular expressions. Saašha Metsärantala++ - Remove unneeded dependencies. - Review regular expressions for QNames. Saašha Metsärantala++ - Updated: Copyright 2012. 0.002 2011-11-09 [ Bug Fixes ] - Occasionally a new prefix was defined when we could have reused an old one. [ Packaging ] - Module::Package::RDF [ Other ] - Updated: use 5.010 0.001 2010-09-06 Initial release INSTALL000664001750001750 167212404152732 13552 0ustar00taitai000000000000RDF-Prefixes-0.005 Installing RDF-Prefixes should be straightforward. INSTALLATION WITH CPANMINUS If you have cpanm, you only need one line: % cpanm RDF::Prefixes 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::Prefixes INSTALLATION WITH THE CPAN SHELL Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan RDF::Prefixes 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-Prefixes: % 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 4365512404152732 13555 0ustar00taitai000000000000RDF-Prefixes-0.005This 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 33512404152737 13632 0ustar00taitai000000000000RDF-Prefixes-0.005CONTRIBUTING COPYRIGHT CREDITS Changes INSTALL LICENSE MANIFEST META.json META.yml Makefile.PL README SIGNATURE dist.ini doap.ttl examples/basic.pl lib/RDF/Prefixes.pm t/01basic.t t/02warnings.t t/03prefixes.t t/04utf8.t META.json000664001750001750 330312404152737 14140 0ustar00taitai000000000000RDF-Prefixes-0.005{ "abstract" : "simple way to turn URIs into QNames", "author" : [ "Toby Inkster ", "TOBYINK " ], "dynamic_config" : 0, "generated_by" : "Moose::Meta::Class::__ANON__::SERIAL::10 version , CPAN::Meta::Converter version 2.140640", "keywords" : [ "Namespace", "Namespaces", "Prefix", "Prefixes", "RDF", "xmlns" ], "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "RDF-Prefixes", "no_index" : { "directory" : [ "eg", "examples", "inc", "t", "xt" ] }, "optional_features" : {}, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.17" } }, "test" : { "requires" : { "Test::More" : "0.61", "Test::Warn" : "0" } } }, "provides" : { "RDF::Prefixes" : { "file" : "lib/RDF/Prefixes.pm", "version" : "0.005" } }, "release_status" : "stable", "resources" : { "X_identifier" : "http://purl.org/NET/cpan-uri/dist/RDF-Prefixes/project", "bugtracker" : { "web" : "http://rt.cpan.org/Dist/Display.html?Queue=RDF-Prefixes" }, "homepage" : "https://metacpan.org/release/RDF-Prefixes", "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "type" : "git", "url" : "git://github.com/tobyink/p5-rdf-prefixes.git", "web" : "https://github.com/tobyink/p5-rdf-prefixes" } }, "version" : "0.005" } META.yml000664001750001750 204612404152736 13772 0ustar00taitai000000000000RDF-Prefixes-0.005--- abstract: 'simple way to turn URIs into QNames' author: - 'Toby Inkster ' - 'TOBYINK ' build_requires: Test::More: '0.61' Test::Warn: '0' configure_requires: ExtUtils::MakeMaker: '6.17' dynamic_config: 0 generated_by: 'Moose::Meta::Class::__ANON__::SERIAL::10 version , CPAN::Meta::Converter version 2.140640' keywords: - Namespace - Namespaces - Prefix - Prefixes - RDF - xmlns license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: RDF-Prefixes no_index: directory: - eg - examples - inc - t - xt optional_features: {} provides: RDF::Prefixes: file: lib/RDF/Prefixes.pm version: '0.005' resources: X_identifier: http://purl.org/NET/cpan-uri/dist/RDF-Prefixes/project bugtracker: http://rt.cpan.org/Dist/Display.html?Queue=RDF-Prefixes homepage: https://metacpan.org/release/RDF-Prefixes license: http://dev.perl.org/licenses/ repository: git://github.com/tobyink/p5-rdf-prefixes.git version: '0.005' Makefile.PL000664001750001750 1137412404152737 14520 0ustar00taitai000000000000RDF-Prefixes-0.005use strict; use ExtUtils::MakeMaker 6.17; my $EUMM = eval( $ExtUtils::MakeMaker::VERSION ); my $meta = { "abstract" => "simple way to turn URIs into QNames", "author" => [ "Toby Inkster ", "TOBYINK ", ], "dynamic_config" => 0, "generated_by" => "Moose::Meta::Class::__ANON__::SERIAL::10 version , CPAN::Meta::Converter version 2.140640", "keywords" => ["Namespace", "Namespaces", "Prefix", "Prefixes", "RDF", "xmlns"], "license" => ["perl_5"], "meta-spec" => { url => "http://search.cpan.org/perldoc?CPAN::Meta::Spec", version => 2, }, "name" => "RDF-Prefixes", "no_index" => { directory => ["eg", "examples", "inc", "t", "xt"] }, "prereqs" => { configure => { requires => { "ExtUtils::MakeMaker" => 6.17 } }, test => { requires => { "Test::More" => 0.61, "Test::Warn" => 0 } }, }, "provides" => { "RDF::Prefixes" => { file => "lib/RDF/Prefixes.pm", version => 0.005 }, }, "release_status" => "stable", "resources" => { bugtracker => { web => "http://rt.cpan.org/Dist/Display.html?Queue=RDF-Prefixes", }, homepage => "https://metacpan.org/release/RDF-Prefixes", license => ["http://dev.perl.org/licenses/"], repository => { type => "git", url => "git://github.com/tobyink/p5-rdf-prefixes.git", web => "https://github.com/tobyink/p5-rdf-prefixes", }, X_identifier => "http://purl.org/NET/cpan-uri/dist/RDF-Prefixes/project", }, "version" => 0.005, }; 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 1015712404152732 13417 0ustar00taitai000000000000RDF-Prefixes-0.005NAME RDF::Prefixes - simple way to turn URIs into QNames SYNOPSIS my $context = RDF::Prefixes->new; say $context->qname('http://purl.org/dc/terms/title'); # dc:title say $context->qname('http://example.net/rdf/dc#title'); # dc2:title say $context->turtle; # @prefix dc: . # @prefix dc2: . DESCRIPTION This module is not so much for managing namespaces/prefixes in code (see RDF::Trine::NamespaceMap for that), but as a helper for code that serialises data using namespaces. It generates pretty prefixes, reducing "http://purl.org/dc/terms/" to "dc" rather than something too generic like like "ns01", and provides a context for keeping track of namespaces already used, so that when "http://purl.org/dc/elements/1.1/" is encountered, it won't stomp on the previous definition of "dc". Constructor `new(\%suggestions, \%options)` Creates a new RDF prefix context. Suggestions for prefix mappings may be given, but there's no guarantee that they'll be used. The only option right now is 'syntax' that is used by the to_string method. Both hashrefs are optional. Methods `get_prefix($uri)` Gets the prefix associated with a URI. e.g. `get_prefix('http://purl.org/dc/terms/')` might return 'dc'. `get_qname($uri)` Gets a QName for a URI. e.g. `get_qname('http://purl.org/dc/terms/title')` might return 'dc:title'. Some URIs cannot be converted to QNames. In these cases, undef is returned. `get_curie($uri)` As per `get_qname`, but allows for more relaxed return values, suitable for RDFa, Turtle or Notation 3, but not RDF/XML. Should never need to return undef. `preview_prefix($uri)`, `preview_qname($uri)`, `preview_curie($uri)` As per the "get" versions of these methods, but doesn't modify the context. `to_hashref` Returns a hashref of prefix mappings used so far. This is not especially necessary as the object may be treated as a hashref directly: foreach my $prefix (keys %$context) { printf("%s => %s\n", $prefix, $context->{$prefix}); } `TO_JSON` A synonym for to_hashref, provided for the benefit of the JSON package. `rdfa` Return the same data as `to_hashref`, but as a string suitable for placing in an RDFa 1.1 prefix attribute. `sparql` Return the same data as `to_hashref`, but as a string suitable for prefixing a SPARQL query. `turtle` Return the same data as `to_hashref`, but as a string suitable for prefixing a Turtle or Notation 3 file. `xmlns` Return the same data as `to_hashref`, but as a string of xmlns attributes, suitable for use with RDF/XML or RDFa. `to_string` Calls either `rdfa`, `sparql`, `turtle` (the default) or `xmlns`, based on the 'syntax' option passed to the constructor. This module overloads the stringification operator, so explicitly calling to_string is rarely necessary. my $context = RDF::Prefixes->new({}, {syntax=>'turtle'}); my $dc_title = 'http://purl.org/dc/terms/title'; print "# Prefixes\n" . $context; Internationalisation Strings passed to and from this module are expected to be utf8 character strings, not byte strings. This is not explicitly checked for, but will be checked in a future version, so be warned! URIs containing non-Latin characters should "just work". BUGS Please report any bugs to . AUTHOR Toby Inkster . COPYRIGHT Copyright 2010-2013 Toby Inkster This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. DISCLAIMER OF WARRANTIES 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. SIGNATURE000664001750001750 341012404152737 14002 0ustar00taitai000000000000RDF-Prefixes-0.005This 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 34d074a3578aed6df4dbb338b041047a89a1f56c COPYRIGHT SHA1 12446ad6a926fd983c646b228bc13718b40296ab CREDITS SHA1 a7d50a3a458b45c449dc740c4c388675cf11e1e7 Changes SHA1 10537b9740e617c073bd0db13a455568fe822724 INSTALL SHA1 34f5e12514b91055de4b164a1f2327ef5c30ba53 LICENSE SHA1 91e132c46b95b8dc46253f9b456cfdba8d7ccf0a MANIFEST SHA1 b29e612e9558f9329682f86d7a6a8f3d4d65fc7f META.json SHA1 c38a1896e23230647bcf1b8b79c727f5c15d2466 META.yml SHA1 1efd55000643a626abc324b3f3899977530d07a9 Makefile.PL SHA1 d2129c4a3c9b78ba11d65bffade9aa7f1c094375 README SHA1 8eea58c635a8e59e362d0db3e373aef0a6d5468f dist.ini SHA1 3ba9b498d97f5f4749859a8e5b99a2f2a98c094e doap.ttl SHA1 d9583ce26822928bcdd9efbe6945765738be6ef6 examples/basic.pl SHA1 310ca4d26cdb71a2603edd6dd5c604959bde54f3 lib/RDF/Prefixes.pm SHA1 29b9fee3ad503f232fc20e8ed2bfb74d285f1e0f t/01basic.t SHA1 1e6c034760e2ee0fcd3db23f170bceca91778bff t/02warnings.t SHA1 65cf38c24ca5c22d94a2ff5cdeb3b8ed237f3e44 t/03prefixes.t SHA1 25d1bf294484cb8ed45854b2dd653e5035320abd t/04utf8.t -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAlQQ1d8ACgkQzr+BKGoqfTld+ACfc5C7OYUcZHgBx+ADIPms2xoi oKEAoLcVCdlqK/LmtviMxo150LAhHOUs =9Fch -----END PGP SIGNATURE----- dist.ini000664001750001750 7512404152732 14121 0ustar00taitai000000000000RDF-Prefixes-0.005;;class='Dist::Inkt::Profile::TOBYINK' ;;name='RDF-Prefixes' doap.ttl000664001750001750 1316412404152736 14214 0ustar00taitai000000000000RDF-Prefixes-0.005@prefix dc: . @prefix doap: . @prefix doap-changeset: . @prefix doap-deps: . @prefix foaf: . @prefix owl: . @prefix rdfs: . @prefix xsd: . a doap:Project; dc:contributor ; doap-deps:test-requirement [ doap-deps:on "Test::More 0.61"^^doap-deps:CpanId ], [ doap-deps:on "Test::Warn"^^doap-deps:CpanId ]; doap:bug-database ; doap:category [ rdfs:label "RDF" ], [ rdfs:label "Prefixes" ], [ rdfs:label "Prefix" ], [ rdfs:label "Namespace" ], [ rdfs:label "Namespaces" ], [ rdfs:label "xmlns" ]; doap:created "2010-09-04"^^xsd:date; doap:developer ; doap:documenter ; doap:download-page ; doap:homepage ; doap:license ; doap:maintainer ; doap:name "RDF-Prefixes"; doap:programming-language "Perl"; doap:release , , , , ; doap:repository [ a doap:GitRepository; doap:browse ; ]; doap:shortdesc "simple way to turn URIs into QNames"@en; doap:tester . a doap:Version; rdfs:label "Initial release"@en; dc:issued "2010-09-06"^^xsd:date; doap:file-release ; doap:revision "0.001"^^xsd:string. a doap:Version; dc:issued "2011-11-09"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Bugfix; rdfs:label "Occasionally a new prefix was defined when we could have reused an old one."@en; ], [ a doap-changeset:Packaging; rdfs:label "Module::Package::RDF"; ], [ a doap-changeset:Update; rdfs:label "use 5.010"; ]; doap-changeset:versus ; ]; doap:file-release ; doap:revision "0.002"^^xsd:string. a doap:Version; dc:issued "2012-05-31"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Documentation; rdfs:label "Fix typo."@en; doap-changeset:thanks _:B1; ], [ rdfs:label "Review regular expressions for QNames."@en; doap-changeset:thanks _:B1; ], [ rdfs:label "Disallow other vocabularies squatting on 'xsd' prefix."@en; doap-changeset:thanks _:B1; ], [ rdfs:label "Remove some redundant regular expressions."@en; doap-changeset:thanks _:B1; ], [ a doap-changeset:Update; rdfs:label "Copyright 2012."@en; ], [ a doap-changeset:Packaging; rdfs:label "Add test case covering warning message."@en; ], [ a doap-changeset:Packaging; rdfs:label "Add test case covering utf8 support."@en; ], [ rdfs:label "Remove unneeded dependencies."@en ]; doap-changeset:versus ; ]; doap:file-release ; doap:revision "0.003"^^xsd:string. a doap:Version; dc:issued "2013-07-02"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Update; rdfs:label "Copyright 2013."@en; ], [ a doap-changeset:Update; rdfs:label "Drop usage of smartmatch operator."@en; ]; doap-changeset:versus ; ]; doap:file-release ; doap:revision "0.004"^^xsd:string. a doap:Version; dc:identifier "RDF-Prefixes-0.005"^^xsd:string; dc:issued "2014-09-10"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Packaging; rdfs:label "Switch to Dist::Inkt."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.005"^^xsd:string. a foaf:Person; foaf:homepage ; foaf:mbox ; foaf:name "Toby Inkster"; foaf:page ; owl:sameAs . _:B1 a foaf:Person; foaf:mbox_sha1sum "5864440b7beefff0c8811ec0a4ef7bba0804e5fc"; foaf:name "Saašha Metsärantala". basic.pl000664001750001750 101312404152732 15742 0ustar00taitai000000000000RDF-Prefixes-0.005/examples#!/usr/bin/perl use 5.010; use RDF::Prefixes; my $c = RDF::Prefixes->new({DC=>'http://example.com/'}, {syntax=>'sparql'}); say $c->get_qname('http://xmlns.com/foaf/0.1/homepage'); say $c->get_qname('http://xmlns.com/foaf/0.1/'); say $c->get_qname('http://example.com/example'); say $c->get_curie('http://purl.org/dc/terms/title'); say $c->get_curie('http://purl.org/dc/terms/'); say $c->get_curie('http://purl.org/dc/elements/1.0/title'); say $c->get_curie('http://purl.org/dc/elements/1.1/title'); say '----'; say $c; 01basic.t000664001750001750 21012404152732 14336 0ustar00taitai000000000000RDF-Prefixes-0.005/tuse Test::More tests => 3; BEGIN { use_ok('RDF::Prefixes') }; my $context = new_ok 'RDF::Prefixes'; isa_ok $context => 'RDF::Prefixes'; 02warnings.t000664001750001750 25612404152732 15120 0ustar00taitai000000000000RDF-Prefixes-0.005/tuse Test::More tests => 1; use Test::Warn; use RDF::Prefixes; warning_like { RDF::Prefixes->new({ '-x' => 'http://www.example.com/', }) } qr{^Ignored suggestion -x\b}; 03prefixes.t000664001750001750 243412404152732 15136 0ustar00taitai000000000000RDF-Prefixes-0.005/tuse Test::More tests => 10; use RDF::Prefixes; my $context = RDF::Prefixes->new; ok(!keys %$context, "Empty context is really empty." ); $context->preview_prefix('http://example.com/foaf/'); ok(!keys %$context, "preview_prefix does not modify context." ); is($context->get_prefix('http://xmlns.com/foaf/0.1/'), 'foaf', 'sensible prefix chosen - ignores version number'); is($context->get_prefix('http://xmlns.com/foaf/1.0/'), 'foaf2', 'sensible prefix chosen - avoids clash'); is($context->get_prefix('http://example.com/foo.rdf#'), 'foo', 'sensible prefix chosen - ignores extension'); is($context->get_qname('http://example.com/foo.rdf#bar'), 'foo:bar', 'get_qname works'); ok(!defined $context->get_qname('http://example.com/foo.rdf#0'), 'get_qname returns undef appropriately'); my $foo0 = $context->get_curie('http://example.com/foo.rdf#0'); ok($foo0, 'get_curie returns something when get_qname cannot'); is($context->{ substr($foo0, 0, (length $foo0) - 1) }, 'http://example.com/foo.rdf#0', 'get_curie returned something sensible!'); is("$context", <<'TURTLE', "output seems OK"); @prefix foaf: . @prefix foaf2: . @prefix foo: . @prefix foo2: . TURTLE 04utf8.t000664001750001750 225112404152732 14175 0ustar00taitai000000000000RDF-Prefixes-0.005/tuse Test::More tests => 11; use RDF::Prefixes; use utf8; foreach (( ['http://purl.org/dc/terms/' => undef, '/ cannot be qnamed'], ['http://purl.org/dc/terms/tØt' => 'dc:tØt', 'interesting char'], ['http://purl.org/dc/terms/Øt' => 'dc:Øt', 'interesting char at start'], ['http://purl.org/tøt/foo' => 'tøt:foo', 'interesting char in prefix'], ['http://purl.org/øt/foo' => 'øt:foo', 'interesting char at start of prefix'], ['http://purl.org/tØt/foo' => 'tøt:foo', 'interesting char in prefix, lowercased'], ['http://purl.org/Øt/foo' => 'øt:foo', 'interesting char at start of prefix, lowercased'], ['http://example.com/τωβυ#ινκστερ' => 'τωβυ:ινκστερ', 'some Greek letters'], ['http://example.com/Τωβυ#Ινκστερ' => 'τωβυ:Ινκστερ', 'some Greek letters, lowercased'], ['http://example.com/トビー#インケ' => 'トビー:インケ', 'some katakana'], ['http://example.com/𝕥𝕠𝕓𝕪/𝕚𝕟𝕜𝕤𝕥𝕖𝕣' => '𝕥𝕠𝕓𝕪:𝕚𝕟𝕜𝕤𝕥𝕖𝕣', 'some non-BMP characters'], )) { is( RDF::Prefixes->new->get_qname($_->[0]), $_->[1], ($_->[2] // $_->[1]), ); } Prefixes.pm000664001750001750 2347112404152732 16046 0ustar00taitai000000000000RDF-Prefixes-0.005/lib/RDFpackage RDF::Prefixes; use 5.010; use strict; use constant { IDX_USED => 0, IDX_SUGGESTED => 1, IDX_OPTIONS => 2, NEXT_IDX => 3, }; use overload '%{}' => \&to_hashref; use overload '""' => \&to_string; use utf8; BEGIN { eval 'use Carp qw(carp); 1' or eval 'sub carp { warn "$_[0]\n" }' } BEGIN { $RDF::Prefixes::AUTHORITY = 'cpan:TOBYINK'; $RDF::Prefixes::VERSION = '0.005'; } # These are the rules from Turtle (W3C WD, dated 09 Aug 2011). # XML 1.0 5e's syntax for XML names (i.e. element names, # attribute names, etc) appears to be pretty similar except # that it allows names to start with a colon or full-stop. # (The former would violate XML namespaces, but is allowed by # XML itself - apparently.) # # So anyway, we go with Turtle as that is the more restrictive # syntax, thus any valid Turtle names should automatically be # valid XML names. # my $PN_CHARS_BASE = qr<(?: [A-Z] | [a-z] | [\x{00C0}-\x{00D6}] | [\x{00D8}-\x{00F6}] | [\x{00F8}-\x{02FF}] | [\x{0370}-\x{037D}] | [\x{037F}-\x{1FFF}] | [\x{200C}-\x{200D}] | [\x{2070}-\x{218F}] | [\x{2C00}-\x{2FEF}] | [\x{3001}-\x{D7FF}] | [\x{F900}-\x{FDCF}] | [\x{FDF0}-\x{FFFD}] | [\x{10000}-\x{EFFFF}] )>x; my $PN_CHARS_U = qr<(?: $PN_CHARS_BASE | [_] )>x; my $PN_CHARS = qr<(?: $PN_CHARS_U | [0-9-] | [\x{00B7}] | [\x{0300}-\x{036F}] | [\x{203F}-\x{2040}] )>x; my $PN_PREFIX = qr< $PN_CHARS_BASE (?: (?: $PN_CHARS | [.] )* $PN_CHARS )? >x; my $PN_LOCAL = qr< (?: $PN_CHARS_U ) # change from Turtle: disallow digits here (?: (?: $PN_CHARS | [.] )* $PN_CHARS )? >x; sub new { my ($class, $suggested, $options) = @_; $suggested ||= {}; $options ||= {}; my $self = [{}, {}, $options]; foreach my $s (reverse sort keys %$suggested) { if ($s =~ m< ^ $PN_PREFIX $ >ix) { $self->[IDX_SUGGESTED]{ $suggested->{$s} } = $s; } else { carp "Ignored suggestion $s => " . $suggested->{$s}; } } bless $self, $class; } sub get_prefix { my ($self, $url) = @_; my $pp = $self->_practical_prefix($url); $self->{ $pp } = $url; return $pp; } sub preview_prefix { shift->_practical_prefix(@_); } sub _valid_qname { my ($self, $p, $l) = @_; return undef unless defined $p && defined $l; return undef unless $l =~ m< ^ $PN_LOCAL $ >x; join q(:) => ($p, $l); } sub get_qname { my ($self, $url) = @_; my ($p, $s) = $self->_split_qname($url); return undef unless defined $p and defined $s; return $self->_valid_qname($self->get_prefix($p), $s); } sub preview_qname { my ($self, $url) = @_; my ($p, $s) = $self->_split_qname($url); return undef unless defined $p and defined $s; return $self->_valid_qname($self->preview_prefix($p), $s); } sub get_curie { my ($self, $url) = @_; my ($p, $s) = $self->_split_qname($url); return $self->get_prefix($url) . ':' unless defined $p and defined $s; return $self->get_prefix($p) . ':' . $s; } sub preview_curie { my ($self, $url) = @_; my ($p, $s) = $self->_split_qname($url); return $self->preview_prefix($url) . ':' unless defined $p and defined $s; return $self->preview_prefix($p) . ':' . $s; } sub to_hashref { my ($self) = @_; $self->[IDX_USED] ||= {}; return $self->[IDX_USED]; } *TO_JSON = \&to_hashref; sub rdfa { my ($self) = @_; my $rv; foreach my $prefix (sort keys %$self) { $rv .= sprintf("%s: %s ", $prefix, $self->{$prefix}); } return substr($rv, 0, (length $rv) - 1); } sub sparql { my ($self) = @_; my $rv; foreach my $prefix (sort keys %$self) { $rv .= sprintf("PREFIX %s: <%s>\n", $prefix, $self->{$prefix}); } return $rv; } sub turtle { my ($self) = @_; my $rv; foreach my $prefix (sort keys %$self) { $rv .= sprintf("\@prefix %-6s <%s> .\n", $prefix.':', $self->{$prefix}); } return $rv; } sub xmlns { my ($self) = @_; my $rv; foreach my $prefix (sort keys %$self) { $rv .= sprintf(" xmlns:%s=\"%s\"", $prefix, $self->{$prefix}); } return $rv; } sub to_string { my ($self) = @_; if (lc $self->[IDX_OPTIONS]{syntax} eq 'rdfa') { return $self->rdfa; } elsif (lc $self->[IDX_OPTIONS]{syntax} eq 'sparql') { return $self->sparql; } elsif (lc $self->[IDX_OPTIONS]{syntax} eq 'xmlns') { return $self->xmlns; } else { return $self->turtle; } } sub _split_qname { my ($self, $uri) = @_; if ($uri =~ m< ($PN_LOCAL) $ >x) { my $ln = $1; my $ns = substr($uri, 0, length($uri)-length($ln)); return ($ns, $ln); } return; } my $looks_like_version = qr< ^ [0-9\.-]+ $ >x; my $too_generic = qr< ^(?: terms|ns|vocab|vocabulary|rdf|rdfs|owl|schema|xsd )$ >x; sub _perfect_prefix { my ($self, $url) = @_; my $chosen = { 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' => 'rdf', 'http://www.w3.org/2000/01/rdf-schema#' => 'rdfs', 'http://www.w3.org/2002/07/owl#' => 'owl', 'http://www.w3.org/2001/XMLSchema#' => 'xsd', 'http://schema.org/' => 'schema', }->{$url}; return $chosen if length $chosen; my @words = map { lc; } ($url =~ m< ((?:$PN_CHARS|\.)+) >xg); WORD: while (defined(my $w = pop @words)) { next WORD if ( length $w < 1 or $w =~ $looks_like_version or $w =~ $too_generic or $w !~ m< ^ $PN_PREFIX $ >x ); $chosen = $w; last WORD; } $chosen =~ s< [.] (owl|rdf|rdfx|rdfs|nt|ttl|turtle|xml|org|com|net) $ >()x; $chosen = 'ex' if $chosen eq 'example'; return undef unless length $chosen; return lc $chosen; } sub _practical_prefix { my ($self, $url) = @_; my %existing = %{ $self->[IDX_USED] }; while (my ($existing_prefix, $full) = each %existing) { return $existing_prefix if $full eq $url; } my $perfect = $self->[IDX_SUGGESTED]{$url} // $self->_perfect_prefix($url) // 'ns'; return $perfect unless $self->_already($perfect); my $i = 2; while ($self->_already($perfect.$i)) { $i++; } return $perfect.$i; } sub _already { my ($self, $prefix) = @_; return grep { uc $prefix eq uc $_ } keys %$self; } 1; __END__ =head1 NAME RDF::Prefixes - simple way to turn URIs into QNames =head1 SYNOPSIS my $context = RDF::Prefixes->new; say $context->qname('http://purl.org/dc/terms/title'); # dc:title say $context->qname('http://example.net/rdf/dc#title'); # dc2:title say $context->turtle; # @prefix dc: . # @prefix dc2: . =head1 DESCRIPTION This module is not so much for managing namespaces/prefixes in code (see L for that), but as a helper for code that serialises data using namespaces. It generates pretty prefixes, reducing "http://purl.org/dc/terms/" to "dc" rather than something too generic like like "ns01", and provides a context for keeping track of namespaces already used, so that when "http://purl.org/dc/elements/1.1/" is encountered, it won't stomp on the previous definition of "dc". =head2 Constructor =over 4 =item C<< new(\%suggestions, \%options) >> Creates a new RDF prefix context. Suggestions for prefix mappings may be given, but there's no guarantee that they'll be used. The only option right now is 'syntax' that is used by the to_string method. Both hashrefs are optional. =back =head2 Methods =over 4 =item C<< get_prefix($uri) >> Gets the prefix associated with a URI. e.g. C<< get_prefix('http://purl.org/dc/terms/') >> might return 'dc'. =item C<< get_qname($uri) >> Gets a QName for a URI. e.g. C<< get_qname('http://purl.org/dc/terms/title') >> might return 'dc:title'. Some URIs cannot be converted to QNames. In these cases, undef is returned. =item C<< get_curie($uri) >> As per C, but allows for more relaxed return values, suitable for RDFa, Turtle or Notation 3, but not RDF/XML. Should never need to return undef. =item C<< preview_prefix($uri) >>, C<< preview_qname($uri) >>, C<< preview_curie($uri) >> As per the "get" versions of these methods, but doesn't modify the context. =item C<< to_hashref >> Returns a hashref of prefix mappings used so far. This is not especially necessary as the object may be treated as a hashref directly: foreach my $prefix (keys %$context) { printf("%s => %s\n", $prefix, $context->{$prefix}); } =item C<< TO_JSON >> A synonym for to_hashref, provided for the benefit of the L package. =item C<< rdfa >> Return the same data as C, but as a string suitable for placing in an RDFa 1.1 prefix attribute. =item C<< sparql >> Return the same data as C, but as a string suitable for prefixing a SPARQL query. =item C<< turtle >> Return the same data as C, but as a string suitable for prefixing a Turtle or Notation 3 file. =item C<< xmlns >> Return the same data as C, but as a string of xmlns attributes, suitable for use with RDF/XML or RDFa. =item C<< to_string >> Calls either C, C, C (the default) or C, based on the 'syntax' option passed to the constructor. This module overloads the stringification operator, so explicitly calling to_string is rarely necessary. my $context = RDF::Prefixes->new({}, {syntax=>'turtle'}); my $dc_title = 'http://purl.org/dc/terms/title'; print "# Prefixes\n" . $context; =back =head2 Internationalisation Strings passed to and from this module are expected to be utf8 character strings, not byte strings. This is not explicitly checked for, but will be checked in a future version, so be warned! URIs containing non-Latin characters should "just work". =head1 BUGS Please report any bugs to L. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT Copyright 2010-2013 Toby Inkster This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 DISCLAIMER OF WARRANTIES 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.