authority::shared(3pm) User Contributed Perl Documentation authority::shared(3pm)NAME
authority::shared - a multi-AUTHORITY method for your classes
SYNOPSIS
package MyApp;
BEGIN { $MyApp::AUTHORITY = 'cpan:JOE'; }
use authority::shared qw(cpan:ALICE cpan:BOB);
package main;
use feature qw(say);
say scalar 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
DESCRIPTION
This module allows you to indicate that your module is issued by multiple authorities. The package variable $AUTHORITY should still be used
to indicate the primary authority for the package.
This module does two simple things:
1. Creates an @AUTHORITIES array in the caller package, populating it with the arguments passed to "authority::shared" on the "use" line.
2. Exports an AUTHORITY function to your package that reads the $AUTHORITY and @AUTHORITIES package variables.
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, "http://datetime.perl.org/", "http://moose.iinteractive.com/" or "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.
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 http://rt.cpan.org/Dist/Display.html?Queue=authority-shared
<http://rt.cpan.org/Dist/Display.html?Queue=authority-shared>.
SEE ALSO
o Object::AUTHORITY - an AUTHORITY method for your class
o authority::shared (this module) - a more sophisticated AUTHORITY method for your class
o UNIVERSAL::AUTHORITY - an AUTHORITY method for every class (deprecated)
o UNIVERSAL::AUTHORITY::Lexical - an AUTHORITY method for every class, within a lexical scope
o authority - load modules only if they have a particular authority
Background reading: <http://feather.perl6.nl/syn/S11.html>, <http://www.perlmonks.org/?node_id=694377>.
AUTHOR
Toby Inkster <tobyink@cpan.org>.
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.
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.
perl v5.14.2 2011-12-15 authority::shared(3pm)
Check Out this Related Man Page
Object::Role(3pm) User Contributed Perl Documentation Object::Role(3pm)NAME
Object::Role - base class for non-Moose roles
SYNOPSIS
{
package Object::Dumpable;
use base qw/Object::Role/;
use Data::Dumper;
sub import
{
my ($class, @args) = @_;
my ($caller, %args) = __PACKAGE__->parse_arguments(undef, @args);
my $coderef = sub
{
my ($self) = @_;
return Dumper($self);
};
__PACKAGE__->install_method(dump => $coderef, $caller);
}
}
{
package Foo;
use Object::Dumpable;
sub new { ... }
}
{
package main;
my $foo = Foo->new;
warn $foo->dump;
}
DESCRIPTION
This will be better documented once I fully understand it myself!
The idea of this is to be a base class for roles like Object::DOES, Object::Stash and Object::ID. It handles parsing of import arguments,
installing methods into the caller's namespace (like Exporter, but using a technique that is immune to namespace::autoclean) and tracking
which packages have consumed your role.
While "Object::Role" is a base class for roles, it is not itself a role, so does not export anything. Instead, your role must inherit from
it.
Methods
"parse_arguments($default_arg_name, @arguments)"
Will parse:
package My::Class;
use My::Role -foo => 1, -bar => [2,3], 4, 5;
as:
(
'My::Class', # caller,
(
'-foo' => [1],
'-bar' => [2, 3],
$default_arg_name => [4, 5],
)
)
"install_method($subname => $coderef, $package)"
Installs $coderef as "$package::$subname".
Automatically calls register_consumer($package).
"register_consumer($package)"
Records that $package has consumed (used) your role.
"has_consumer($package)"
Check if $package has consumed (used) your role.
BUGS
Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=Object-Role <http://rt.cpan.org/Dist/Display.html?Queue=Object-Role>.
SEE ALSO
Object::DOES, Object::AUTHORITY.
AUTHOR
Toby Inkster <tobyink@cpan.org>.
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.
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.
perl v5.14.2 2011-12-15 Object::Role(3pm)