1. Toby Inkster
  2. p5-authority-shared

Commits

Toby Inkster  committed a48ca88

authority related packages

  • Participants
  • Branches authority-shared

Comments (0)

Files changed (14)

File Makefile.PL

View file
+use inc::Module::Package 'RDF:standard';
+

File examples/basic.pl

View file
+package Local::Module;
+BEGIN { $Local::Module::AUTHORITY = 'cpan:TOBYINK' ; }
+use authority::shared qw(http://tobyinkster.co.uk/ mailto:tobyink@cpan.org);
+
+package main;
+use 5.010;
+use Data::Dumper;
+say Local::Module->AUTHORITY('cpan:TOBYINK');
+say Local::Module->AUTHORITY('mailto:tobyink@cpan.org');
+say Local::Module->AUTHORITY('cpan:JOE'); # should die

File lib/authority/shared.pm

View file
+package authority::shared;
+
+use 5.005;
+use strict;
+use UNIVERSAL::AUTHORITY 0.002 qw();
+
+BEGIN {
+	$authority::shared::AUTHORITY = 'cpan:TOBYINK';
+	$authority::shared::VERSION   = '0.002';
+}
+
+use Carp qw(croak);
+use Scalar::Util qw(blessed);
+use Sub::Name qw(subname); # protects against namespace::autoclean.
+
+sub import
+{
+	shift if $_[0] eq __PACKAGE__;
+	my ($caller) = caller;
+	
+	no strict 'refs';
+	push @{"$caller\::AUTHORITIES"}, @_;
+	*{"$caller\::AUTHORITY"} = subname("$caller\::AUTHORITY", \&AUTHORITY);
+}
+
+sub AUTHORITY
+{
+	my ($invocant, $test) = @_;
+	$invocant = ref $invocant if blessed($invocant);
+	
+	my @authorities = do {
+		no strict 'refs';
+		my @a = @{"$invocant\::AUTHORITIES"};
+		unshift @a, ${"$invocant\::AUTHORITY"};
+		@a;
+		};
+	
+	if (scalar @_ > 1)
+	{
+		my $pass = undef;
+		AUTH: for (@authorities)
+		{
+			next AUTH
+				unless UNIVERSAL::AUTHORITY::reasonably_smart_match($_, $test);
+			$pass = $_;
+			last AUTH;
+		}
+		croak("Invocant ($invocant) has authority '$authorities[0]'")
+			unless defined $pass;
+		return $pass;
+	}
+	
+	return wantarray ? @authorities : $authorities[0];
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+authority::shared - a multi-AUTHORITY method for your classes
+
+=head1 SYNOPSIS
+
+ package MyApp;
+ BEGIN { $MyApp::AUTHORITY = 'cpan:JOE'; }
+ use authority::shared qw(cpan:ALICE cpan:BOB);
+ 
+ package main;
+ use feature qw(say);
+ say MyApp->AUTHORITY;  # says "cpan:JOE"
+ MyApp->AUTHORITY('cpan:JOE');    # lives
+ MyApp->AUTHORITY('cpan:ALICE');  # lives
+ MyApp->AUTHORITY('cpan:BOB');    # lives
+ MyApp->AUTHORITY('cpan:CAROL');  # croaks
+
+=head1 DESCRIPTION
+
+This module allows you to indicate that your module is issued by multiple
+authorities. The package variable C<< $AUTHORITY >> should still be used
+to indicate the primary authority for the package.
+
+This module does two simple things:
+
+=over
+
+=item 1. Creates an C<< @AUTHORITIES >> array in the caller package,
+populating it with the arguments passed to C<< authority::shared >>
+on the "use" line.
+
+=item 2. Exports an AUTHORITY function to your package that reads the
+C<< $AUTHORITY >> and C<< @AUTHORITIES >> package variables.
+
+=back
+
+The main use case for shared authorities is for team projects. The team
+would designate a URI to represent the team as a whole. For example, 
+C<< http://datetime.perl.org/ >>, C<< http://moose.iinteractive.com/ >> 
+or C<< http://www.perlrdf.org/ >>. Releases can then be officially stamped
+with the authority of the team using:
+
+ use authority::shared q<http://www.perlrdf.org/>;
+
+And users can check they have an module released by the official team
+using:
+
+ RDF::TakeOverTheWorld->AUTHORITY(q<http://www.perlrdf.org/>);
+
+which will croak if package RDF::TakeOverTheWorld doesn't have the
+specified authority.
+
+=head1 BUGS
+
+An obvious limitation is that this module relies on honesty. Don't
+release modules under authorities you have no authority to use.
+
+Please report any bugs to
+L<http://rt.cpan.org/Dist/Display.html?Queue=authority-shared>.
+
+=head1 SEE ALSO
+
+L<UNIVERSAL::AUTHORITY>,
+L<authority>,
+L<http://feather.perl6.nl/syn/S11.html>,
+L<http://www.perlmonks.org/?node_id=694377>.
+
+=head1 AUTHOR
+
+Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
+
+=head1 COPYRIGHT AND LICENCE
+
+This software is copyright (c) 2011 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.
+
+=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.
+

File meta/changes.ttl

View file
+# This file acts as the project's changelog.
+
+@prefix :        <http://usefulinc.com/ns/doap#> .
+@prefix dcs:     <http://ontologi.es/doap-changeset#> .
+@prefix dc:      <http://purl.org/dc/terms/> .
+@prefix dist:    <http://purl.org/NET/cpan-uri/dist/authority-shared/> .
+@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .
+
+dist:project :release dist:v_0-001 .
+dist:v_0-001
+	a               :Version ;
+	dc:issued       "2011-11-06"^^xsd:date ;
+	:revision       "0.001"^^xsd:string ;
+	:file-release   <http://backpan.cpan.org/authors/id/T/TO/TOBYINK/authority-shared-0.001.tar.gz> ;
+	rdfs:label      "Initial release" .
+
+dist:project :release dist:v_0-002 .
+dist:v_0-002
+	a               :Version ;
+	dc:issued       "2011-11-06"^^xsd:date ;
+	:revision       "0.002"^^xsd:string ;
+	:file-release   <http://backpan.cpan.org/authors/id/T/TO/TOBYINK/authority-shared-0.002.tar.gz> ;
+	dcs:changeset [
+		dcs:versus dist:v_0-001 ;
+		dcs:item   [ rdfs:label "Offer protection against namespace::clean stripping the AUTHORITY method straight back out of the function."@en ]
+		] .

File meta/doap.ttl

View file
+# This file contains general metadata about the project.
+
+@prefix :        <http://usefulinc.com/ns/doap#> .
+@prefix dc:      <http://purl.org/dc/terms/> .
+@prefix foaf:    <http://xmlns.com/foaf/0.1/> .
+@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .
+
+<http://purl.org/NET/cpan-uri/dist/authority-shared/project>
+	a               :Project ;
+	:programming-language "Perl" ;
+	:name           "authority-shared" ;
+	:shortdesc      "a multi-AUTHORITY method for your classes" ;
+	:homepage       <https://metacpan.org/release/authority-shared> ;
+	:download-page  <https://metacpan.org/release/authority-shared> ;
+	:bug-database   <http://rt.cpan.org/Dist/Display.html?Queue=authority-shared> ;
+	:created        "2011-11-06"^^xsd:date ;
+	:license        <http://dev.perl.org/licenses/> ;
+	:developer      [ a foaf:Person ; foaf:name "Toby Inkster" ; foaf:mbox <mailto:tobyink@cpan.org> ] .
+
+<http://dev.perl.org/licenses/>
+	dc:title        "the same terms as the perl 5 programming language system itself" .
+

File meta/makefile.ttl

View file
+# This file provides instructions for packaging.
+
+@prefix : <http://purl.org/NET/cpan-uri/terms#> .
+
+<http://purl.org/NET/cpan-uri/dist/authority-shared/project>
+	:perl_version_from _:main ;
+	:version_from _:main ;
+	:readme_from _:main ;
+	:test_requires "Test::More 0.61" , "Test::Exception" ;
+	:requires "Scalar::Util" , "Carp" , "UNIVERSAL::AUTHORITY 0.002" .
+
+_:main <http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#fileName> "lib/authority/shared.pm" .
+

File t/01basic.t

View file
+use Test::More tests => 1;
+BEGIN { use_ok('authority::shared') };
+

File t/02as.t

View file
+package Local::Module;
+BEGIN { $Local::Module::AUTHORITY = 'cpan:TOBYINK' ; }
+use authority::shared qw(http://tobyinkster.co.uk/ mailto:tobyink@cpan.org);
+
+package main;
+use Test::More tests => 3;
+use Test::Exception;
+
+is (
+	Local::Module->AUTHORITY('cpan:TOBYINK'),
+	'cpan:TOBYINK',
+	);
+
+is (
+	Local::Module->AUTHORITY('mailto:tobyink@cpan.org'),
+	'mailto:tobyink@cpan.org',
+	);
+
+dies_ok { Local::Module->AUTHORITY('cpan:JOE') };

File t/03nc.t

View file
+use Test::More;
+use lib ".";
+use lib "t";
+
+plan skip_all => 'Need Sub::Name'
+	unless eval 'require Sub::Name; 1';
+
+plan skip_all => 'Need Devel::Sub::Which'
+	unless eval 'require Devel::Sub::Which; 1';
+
+plan skip_all => 'Need namespace::autoclean'
+	unless eval 'require namespace::autoclean; 1';
+
+require Example89; 
+plan tests => 2;
+is(
+	Example89->which('AUTHORITY'),
+	'Example89::AUTHORITY'
+	);
+is(
+	Example89->AUTHORITY('http://tobyinkster.co.uk/#i'),
+	'http://tobyinkster.co.uk/#i'
+	);

File t/Example89.pm

View file
+package Example89;
+
+BEGIN {
+	$Example89::AUTHORITY = 'cpan:TOBYINK';
+	$Example89::VERSION   = '1.234';
+}
+
+use authority::shared q<http://tobyinkster.co.uk/#i>;
+use namespace::autoclean;
+use Devel::Sub::Which qw(:universal);
+
+1;

File xt/01pod.t

View file
+use Test::More;
+eval "use Test::Pod 1.00";
+plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
+all_pod_files_ok();
+

File xt/02pod_coverage.t

View file
+use Test::More;
+use Test::Pod::Coverage;
+
+my @modules = qw(authority::shared);
+pod_coverage_ok($_, "$_ is covered")
+	foreach @modules;
+done_testing(scalar @modules);
+

File xt/03meta_uptodate.t

View file
+use Test::More tests => 1;
+use Test::RDF::DOAP::Version;
+doap_version_ok('authority-shared', 'authority::shared');
+

File xt/04eol.t

View file
+use Test::EOL;
+all_perl_files_ok();