| 1 | package UNIVERSAL::moniker; | ||||||||||||||||||||
| 2 | 1 | $UNIVERSAL::moniker::VERSION = '0.08'; | |||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | =head1 NAME | ||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | UNIVERSAL::moniker | ||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | =head1 SYNOPSIS | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | use UNIVERSAL::moniker; | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | =head1 DESCRIPTION | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | Class names in Perl often don't sound great when spoken, or look good when | ||||||||||||||||||||
| 15 | written in prose. For this reason, we tend to say things like "customer" or | ||||||||||||||||||||
| 16 | "basket" when we are referring to C<My::Site::User::Customer> or | ||||||||||||||||||||
| 17 | C<My::Site::Shop::Basket>. We thought it would be nice if our classes knew what | ||||||||||||||||||||
| 18 | we would prefer to call them. | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | This module will add a C<moniker> (and C<plural_moniker>) method to | ||||||||||||||||||||
| 21 | C<UNIVERSAL>, and so to every class or module. | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | =head2 moniker | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | $ob->moniker; | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | Returns the moniker for $ob. | ||||||||||||||||||||
| 28 | So, if $ob->isa("Big::Scary::Animal"), C<moniker> will return "animal". | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | =head2 plural_moniker | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | $ob->plural_moniker; | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | Returns the plural moniker for $ob. | ||||||||||||||||||||
| 35 | So, if $ob->isa("Cephalopod::Octopus"), C<plural_moniker> will return "octopuses". | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | (You need to install Lingua::EN::Inflect for this to work.) | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | =cut | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | package UNIVERSAL; | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 2 | ▶ | sub moniker { | ||||||||||||||||||
|
Subroutine
moniker: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||
| 44 | 2 | ▶ | (ref( $_[0] ) || $_[0]) =~ /([^:]+)$/; | ||||||||||||||||||
|
Condition66%2/3
ref $_[0] || $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table66%2/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||
| 45 | 2 | return lc $1; | |||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 0 | ▶ | sub plural_moniker { | ||||||||||||||||||
|
Subroutine
plural_moniker: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 49 | 0 | CORE::require Lingua::EN::Inflect; | |||||||||||||||||||
| 50 | 0 | return Lingua::EN::Inflect::PL($_[0]->moniker); | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | =head1 AUTHORS | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | Marty Pauley <marty+perl@kasei.com>, | ||||||||||||||||||||
| 56 | Tony Bowden <tony@kasei.com>, | ||||||||||||||||||||
| 57 | Elizabeth Mattijsen <liz@dijkmat.nl> | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | (Yes, 3 authors for such a small module!) | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | =head1 COPYRIGHT | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | Copyright (C) 2004 Kasei | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | This program is free software; you can redistribute it under the same terms as | ||||||||||||||||||||
| 66 | Perl. | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | This program is distributed in the hope that it will be useful, but WITHOUT | ||||||||||||||||||||
| 69 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||||||||||||||||||||
| 70 | FOR A PARTICULAR PURPOSE. | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | =cut | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 1 | 1; | |||||||||||||||||||