AI-MicroStructure

 view release on metacpan or  search on metacpan

lib/AI/MicroStructure/Locale.pm  view on Meta::CPAN

    zero uno due tre quattro cinque sei sette otto nove
    # names yi
    nul eyn tsvey dray fir finf zeks zibn akht nayn

=head1 DESCRIPTION

C<AI::MicroStructure::Locale> is the base class for all structures that are
meant to return a random excerpt from a predefined list I<that depends
on the language>.

The language is selected at construction time from:

=over 4

=item 1.

the given C<lang> or C<category> parameter,

=item 2.

the current locale, as given by the environment variables C<LANGUAGE>,
C<LANG> or (under Win32) Win32::Locale.

=item 3.

the default language for the selected structure.

=back

The language codes should conform to the RFC 3066 and ISO 639 standard.

=head1 METHODS

AI::MicroStructure::Locale offers several methods, so that the subclasses
are easy to write (see full example in L<SYNOPSIS>):

lib/AI/MicroStructure/Locale.pm  view on Meta::CPAN

Return $count names (default: C<1>).

Using C<0> will return the whole list in list context, and the size of the
list in scalar context (according to the C<lang> parameter passed to the
constructor).

=item lang()

=item category()

Return the selected language for this instance.

=item languages()

=item categories()

Return the languages supported by the structure.

=item structure()

Return the structure name.

lib/AI/MicroStructure/MultiList.pm  view on Meta::CPAN

    nine
    # names other
    zero one

=head1 DESCRIPTION

C<AI::MicroStructure::MultiList> is the base class for all structures
that are meant to return a random excerpt from a predefined list
I<divided in categories>.

The category is selected at construction time from:

=over 4

=item 1.

the given C<category> parameter,

=item 2.

the default category for the selected structure.

=back

Categories and sub-categories are separated by a C</> character.

=head1 METHODS

AI::MicroStructure::MultiList offers several methods, so that the subclasses
are easy to write (see full example in L<SYNOPSIS>):

lib/AI/MicroStructure/MultiList.pm  view on Meta::CPAN

=item name( $count )

Return $count names (default: C<1>).

Using C<0> will return the whole list in list context, and the size of the
list in scalar context (according to the C<category> parameter passed to the
constructor).

=item category()

Return the selected category for this instance.

=item categories()

Return the categories supported by the structure (except C<:all>).

=item has_category( $category )

Return a boolean value indicating if the structure contains the given category.

=item structure()

lib/AI/MicroStructure/RemoteList.pm  view on Meta::CPAN


Return the data structure containing the source URLs. This can be quite
different depending on the class: a single scalar (URL), an array
reference (list of URLs) or a hash reference (each value being either
a scalar or an array reference) for structures that are subclasses of
C<AI::MicroStructure::MultiList>.

=item sources( [ $category ] )

Return the list of source URL. The C<$category> parameter can be used
to select the sources for a sub-category of the structure (in the case of
C<AI::MicroStructure::MultiList>).

C<$category> can be an array reference containing a list of categories.

=item extract( $content )

Return a list of items from the C<$content> string. C<$content> is
expected to be the content available at the URL given by C<source()>.

=back

t/t/005.t  view on Meta::CPAN


ok(1);


__DATA__

# "alter" the shuffle method
{
    no warnings;
    my ( $i, $j ) = ( 0, 0 );
    *List::Util::shuffle = sub { sort @_ };    # item selection
    *AI::MicroStructure::any::shuffle =       # theme selection
        sub (@) { my @t = sort @_; push @t, shift @t for 1 .. $j; $j++; @t };
}

# compute the first 6 installed themes
my $meta   = AI::MicroStructure->new("any");
my @themes = ( grep { ! /^any$/ } sort $meta->structures() )[ 0 .. 5 ];

# the test list is computed now because of cache issues
my @tests
    = map { [ ( sort $meta->name( $themes[$_] => 0 ) )[ 0 .. $_ + 1 ] ] }



( run in 0.555 second using v1.01-cache-2.11-cpan-49f99fa48dc )