| 1 | package AI::MicroStructure::any; | ||
| 2 | use strict; | ||
| 3 | use List::Util 'shuffle'; | ||
| 4 | use AI::MicroStructure (); | ||
| 5 | our $VERSION = '1.000'; | ||
| 6 | |||
| 7 | our $Theme = 'any'; | ||
| 8 | |||
| 9 | sub import { | ||
| 10 | # export the metaany function | ||
| 11 | my $callpkg = caller; | ||
| 12 | my $meta = AI::MicroStructure::any->new(); | ||
| 13 | no strict 'refs'; | ||
| 14 | *{"$callpkg\::metaany"} = sub { $meta->name( @_ ) }; | ||
| 15 | } | ||
| 16 | |||
| 17 | sub name { | ||
| 18 | my $self = shift; | ||
| 19 | my $structure = | ||
| 20 | ( shuffle( grep { !/^(?:any|random)$/ } AI::MicroStructure->structures() ) )[0]; | ||
| 21 | $self->{meta}->name( $structure, @_ ); | ||
| 22 | } | ||
| 23 | |||
| 24 | sub new { | ||
| 25 | my $class = shift; | ||
| 26 | |||
| 27 | # we need a full AI::MicroStructure object, to support AMS::Locale | ||
| 28 | return bless { meta => AI::MicroStructure->new( @_ ) }, $class; | ||
| 29 | } | ||
| 30 | |||
| 31 | sub structure { $Theme }; | ||
| 32 | |||
| 33 | sub has_remotelist { }; | ||
| 34 | |||
| 35 | 1; | ||
| 36 | |||
| 37 | =encoding iso-8859-1 | ||
| 38 | |||
| 39 | =head1 NAME | ||
| 40 | |||
| 41 | AI::MicroStructure::any - Items from any structure | ||
| 42 | |||
| 43 | =head1 DESCRIPTION | ||
| 44 | |||
| 45 | This structure simply selects a theme at random from all available | ||
| 46 | structures, and returns names from it. | ||
| 47 | |||
| 48 | The selection is done in such a manner that you'll see no repetition | ||
| 49 | in the items returned from a given structure, until all items from the | ||
| 50 | structure have been seen. | ||
| 51 | |||
| 52 | =head1 METHODS | ||
| 53 | |||
| 54 | =over 4 | ||
| 55 | |||
| 56 | =item new( @args ) | ||
| 57 | |||
| 58 | Create a new instance. | ||
| 59 | |||
| 60 | The parameters will be used to create the underlying AI::MicroStructure | ||
| 61 | object, and will be passed to the randomly chosen structure. This can be | ||
| 62 | useful for structures deriving from AI::MicroStructure::Locale. | ||
| 63 | |||
| 64 | =item name( $count ) | ||
| 65 | |||
| 66 | Implement the name() method for this class. | ||
| 67 | |||
| 68 | =item structure() | ||
| 69 | |||
| 70 | Return the structure name (C<any>). | ||
| 71 | |||
| 72 | =item has_remotelist() | ||
| 73 | |||
| 74 | Always return false. | ||
| 75 | |||
| 76 | =back | ||
| 77 | |||
| 78 | =head1 CONTRIBUTOR | ||
| 79 | |||
| 80 | Philippe Bruhat, upon request of Sébastien Aperghis-Tramoni. | ||
| 81 | |||
| 82 | Introduced in Acme-MetaSyntactic version 0.12, published on March 7, 2005. | ||
| 83 | |||
| 84 | Updated to conform with interface changes required by | ||
| 85 | C<AI::MicroStructure::Updatable> in version 0.49, published | ||
| 86 | on November 21, 2005. | ||
| 87 | |||
| 88 | Received its own version number for Acme-MetaSyntactic version 1.000, | ||
| 89 | published on May 7, 2012. | ||
| 90 | |||
| 91 | =head1 SEE ALSO | ||
| 92 | |||
| 93 | L<AI::MicroStructure>. | ||
| 94 | |||
| 95 | =cut | ||
| 96 |