Commits

Toby Inkster  committed 9cd0dee

authority related packages

  • Participants
  • Parent commits 6186e31

Comments (0)

Files changed (2)

File lib/UNIVERSAL/AUTHORITY.pm

 
 BEGIN {
 	$UNIVERSAL::AUTHORITY::AUTHORITY = 'cpan:TOBYINK';
-	$UNIVERSAL::AUTHORITY::VERSION   = '0.001';
+	$UNIVERSAL::AUTHORITY::VERSION   = '0.002';
 }
 
 use Carp qw[croak];
 
 sub UNIVERSAL::AUTHORITY
 {
-	my ($invocant, $test) = @_;	
+	my ($invocant, $test) = @_;
+	$invocant = ref $invocant if blessed($invocant);
+	
 	my $authority = do {
 		no strict 'refs';
 		${"$invocant\::AUTHORITY"};
 	{
 		if (defined $authority)
 		{
-			croak("Invocant ($invocant) has authority '$authority'.")
-				unless _reasonably_smart_match($authority, $test);
+			croak("Invocant ($invocant) has authority '$authority'")
+				unless reasonably_smart_match($authority, $test);
 		}
 		else
 		{
-			croak("Invocant ($invocant) has no authority defined.")
-				unless _reasonably_smart_match($authority, $test);
+			croak("Invocant ($invocant) has no authority defined")
+				unless reasonably_smart_match($authority, $test);
 		}
 	}
 	
 	return $authority;
 }
 
-sub _reasonably_smart_match
+sub reasonably_smart_match
 {
 	my ($a, $b) = @_;
 	
 	}
 	elsif (ref $b eq 'ARRAY')
 	{
-		return grep { _reasonably_smart_match($a, $_) } @$b;
+		return grep { reasonably_smart_match($a, $_) } @$b;
 	}
 	elsif (ref $b eq 'Regexp')
 	{
 expression, a code reference to use as a callback, or an array reference
 that will be grepped.)
 
+=head2 Utility Function
+
+=over
+
+=item C<< UNIVERSAL::AUTHORITY::reasonably_smart_match($a, $b) >>
+
+UNIVERSAL::AUTHORITY exposes its smart match implementation in case
+classes wish to reuse it for their own custom C<AUTHORITY> methods. (There
+are various interesting use cases for custom C<AUTHORITY> methods, just as
+there are for custom C<can> and C<isa> methods.)
+
+The C<< $a >> parameter is assumed to be a scalar.
+
+=back
+
 =head1 BUGS
 
 Please report any bugs to
 
 =head1 SEE ALSO
 
+L<authority>,
+L<authority::shared>,
+L<http://feather.perl6.nl/syn/S11.html>,
+L<http://www.perlmonks.org/?node_id=694377>.
+
 L<UNIVERSAL>,
 L<UNIVERSAL::which>,
 L<UNIVERSAL::dump>,

File meta/changes.ttl

 	:file-release   <http://backpan.cpan.org/authors/id/T/TO/TOBYINK/UNIVERSAL-AUTHORITY-0.001.tar.gz> ;
 	rdfs:label      "'Twas his intent" .
 
+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/UNIVERSAL-AUTHORITY-0.002.tar.gz> ;
+	dcs:changeset [
+		dcs:versus dist:v_0-001 ;
+		dcs:item   [ rdfs:label "Allow calling as an object method."@en ] ;
+		dcs:item   [ rdfs:label "Expose reaonably_smart_match utility function."@en ] ;
+		dcs:item   [ rdfs:label "Remove trailing full stops from croak messages."@en ]
+		] .