AI-MicroStructure
view release on metacpan or search on metacpan
lib/AI/MicroStructure.pm view on Meta::CPAN
$self->{micro}{$structure} = AI::MicroStructure->new($structure,category => $category);
print $self->{micro}{$structure}->name( $count );
return;
} catch{
}
}
}
}
# corresponding method
sub name {
my $self = shift;
my ( $structure, $count ) = ("any",1);
if (@_) {
( $structure, $count ) = @_;
( $structure, $count ) = ( $self->{structure}, $structure )
if defined($structure) && $structure =~ /^(?:0|[1-9]\d*)$/;
}
else {
( $structure, $count ) = ( $self->{structure}, 1 );
}
if( ! exists $self->{micro}{$structure} ) {
if( ! $MICRO{$structure} ) {
eval "require '$absstructdir/$structure.pm';";
croak "MicroStructure list $structure does not exist!" if $@;
$MICRO{$structure} = 1; # loaded
}
$self->{micro}{$structure} =
"AI::MicroStructure::$structure"->new( %{ $self->{args} } );
}
$self->{micro}{$structure}->name( $count );
}
# corresponding method
sub namex {
my $self = shift;
my ( $structure, $count ) = ("any",1);
if (@_) {
( $structure, $count ) = @_;
( $structure, $count ) = ( $self->{structure}, $structure )
if defined($structure) && $structure =~ /^(?:0|[1-9]\d*)$/;
}
else {
( $structure, $count ) = ( $self->{structure}, 1 );
}
if( ! exists $self->{micro}{$structure} ) {
if( ! $MICRO{$structure} ) {
try {
eval "require '$absstructdir/$structure.pm';";
$MICRO{$structure} = 1; # loaded
croak "MicroStructure list $structure does not exist!" if $@;
}catch{
}
}
$self->{micro}{$structure} =
"AI::MicroStructure::$structure"->new( %{ $self->{args} } );
}
$self->{micro}{$structure}->name( $count );
}
# other methods
sub structures { wantarray ? ( sort keys %MICRO ) : scalar keys %MICRO }
sub has_structure { $_[1] ? exists $MICRO{$_[1]} : 0 }
sub configure_driver { $_[1] ? exists $MICRO{$_[1]} : 0 }
sub count {
my $self = shift;
my ( $structure, $count );
if (@_) {
( $structure, $count ) = @_;
( $structure, $count ) = ( $self->{structure}, $structure )
if $structure =~ /^(?:0|[1-9]\d*)$/;
}
if( ! exists $self->{micro}{$structure} ) {
return scalar ($self->{micro}{$structure}->new);
}
return 0;
}
sub trim
{
my $self = shift;
my $string = shift;
$string = "" unless $string;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
$string =~ s/\t//;
$string =~ s/^\s//;
return $string;
}
sub getBundle {
my $self = shift;
my @structures = grep { !/^(?:any)/ } AI::MicroStructure->structures;
my @micros;
my @search=[];
for my $structure (@structures) {
no strict 'refs';
eval "require '$absstructdir/$structure.pm';";
my %isa = map { $_ => 1 } @{"AI::MicroStructure::$structure\::ISA"};
if( exists $isa{'AI::MicroStructure::Locale'} ) {
for my $lang ( "AI::MicroStructure::$structure"->languages() ) {
push @micros,
["AI::MicroStructure::$structure"->new( lang => $lang ),$lang];
}
}
elsif( exists $isa{'AI::MicroStructure::MultiList'} ) {
for my $cat ( "AI::MicroStructure::$structure"->categories(), ':all' ) {
push @micros,
[ "AI::MicroStructure::$structure"->new( category => $cat ),$cat];
}
}
else {
push @micros, ["AI::MicroStructure::$structure"->new(),''];
}
}
my $all ={};
for my $test (@micros) {
my $micro = $test->[0];
my %items;
my $items = $micro->name(0);
$items{$_}++ for $micro->name(0);
my $key=sprintf("%s",$micro->structure);
$all->{$key}=[$test->[1],$micro->name($items)];
}
return $all;
}
( run in 2.008 seconds using v1.01-cache-2.11-cpan-d8267643d1d )