AI-MicroStructure
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/AI/MicroStructure/RemoteList.pm view on Meta::CPAN
=encoding iso-8859-1
=cut
package AI::MicroStructure::RemoteList;
use strict;
use warnings;
use Carp;
our $VERSION = '0.20';
# method that extracts the items from the remote content and returns them
sub extract {
my $class = ref $_[0] || $_[0];
no strict 'refs';
my $func = ${"$class\::Remote"}{extract};
# provide a very basic default
my $meth = ref $func eq 'CODE'
? sub { my %seen; return grep { !$seen{$_}++ } $func->( $_[1], $_[2] ); }
: sub { return $_[1] }; # very basic default
# put the method in the subclass symbol table (at runtime)
*{"$class\::extract"} = $meth;
# now run the function^Wmethod
goto &$meth;
}
# methods related to the source URL
sub source {
my $class = ref $_[0] || $_[0];
no strict 'refs';
return ${"$class\::Remote"}{source};
}
sub sources {
my $class = ref $_[0] || $_[0];
no strict 'refs';
my $src = ${"$class\::Remote"}{source};
if ( ref $src eq 'ARRAY' ) {
return @$src;
}
elsif ( ref $src eq 'HASH' ) {
return grep $_,
defined $_[1] && $_[1] ne ':all'
? ref $_[1] ? @$src{ @{ $_[1] } }
: $src->{ $_[1] }
: values %$src;
}
return $src;
}
sub has_remotelist { return defined $_[0]->source(); }
# main method: return the list from the remote source
sub remote_list {
my $class = ref $_[0] || $_[0];
return unless $class->has_remotelist();
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.552 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )