use
5.006;
our
$VERSION
=
'1.02'
;
$VERSION
=~ s/_//;
__PACKAGE__->mk_accessors(
qw(_available _total)
);
my
@Plugins
;
my
@SearchPaths
= (
'Module::CPANTS::Kwalitee'
);
my
@Indicators
;
my
%IndicatorHash
;
my
$Total
;
my
$Available
;
sub
import
{
my
(
$class
,
@search_paths
) =
@_
;
for
my
$path
(
@search_paths
) {
next
unless
$path
=~ /^[A-Za-z][A-Za-z0-9_]*(::[A-Za-z][A-Za-z0-9_]*)*$/;
push
@SearchPaths
,
$path
=~ /^Module::CPANTS::/ ?
$path
:
"Module::CPANTS::$path"
;
my
%seen
;
@SearchPaths
=
grep
{!
$seen
{
$_
}++}
@SearchPaths
;
}
}
sub
_load_plugins {
my
$class
=
shift
;
unless
(
@Plugins
) {
my
%seen
;
@Plugins
=
sort
{
$a
->order <=>
$b
->order or
$a
cmp
$b
}
grep
{!
$seen
{
$_
}++}
map
{usesub
$_
}
@SearchPaths
;
$class
->_cache_indicators;
}
}
sub
_cache_indicators {
my
$class
=
shift
;
@Indicators
= ();
$Total
=
$Available
= 0;
for
my
$plugin
(
@Plugins
) {
for
my
$indicator
(@{
$plugin
->kwalitee_indicators}) {
$indicator
->{defined_in} =
$plugin
;
$indicator
->{is_core} = 1
if
!
$indicator
->{is_extra} and !
$indicator
->{is_experimental};
push
@Indicators
,
$indicator
;
$Total
++
unless
$indicator
->{is_experimental};
$Available
++
if
$indicator
->{is_core};
}
}
}
sub
plugins {
@Plugins
}
sub
new {
my
$class
=
shift
;
$class
->_load_plugins;
bless
{},
$class
;
}
sub
generators {
my
$self
=
shift
;
return
\
@Plugins
unless
@_
;
@Plugins
= @{
$_
[0]};
$self
->_cache_indicators;
\
@Plugins
;
}
sub
get_indicators {
my
(
$self
,
$type
) =
@_
;
unless
(
$type
) {
return
wantarray
?
@Indicators
: \
@Indicators
;
}
$type
=
'is_core'
if
$type
eq
'core'
;
$type
=
'is_extra'
if
$type
eq
'optional'
;
$type
=
'is_experimental'
if
$type
eq
'experimental'
;
my
@indicators
;
for
my
$indicator
(
@Indicators
) {
next
if
!
$indicator
->{
$type
};
push
@indicators
,
$indicator
;
}
return
wantarray
?
@indicators
: \
@indicators
;
}
sub
get_indicators_hash {
my
$self
=
shift
;
return
\
%IndicatorHash
if
%IndicatorHash
;
foreach
my
$ind
(
@Indicators
) {
$IndicatorHash
{
$ind
->{name}} =
$ind
;
}
return
\
%IndicatorHash
;
}
sub
available_kwalitee {
$Available
}
sub
total_kwalitee {
$Total
}
sub
_indicator_names {
my
(
$self
,
$coderef
) =
@_
;
my
@names
=
map
{
$_
->{name} }
grep
{
$coderef
->(
$_
)}
$self
->get_indicators;
return
wantarray
?
@names
: \
@names
;
}
sub
all_indicator_names {
shift
->_indicator_names(
sub
{1}) }
sub
core_indicator_names {
shift
->_indicator_names(
sub
{
$_
->{is_core}});
}
sub
optional_indicator_names {
shift
->_indicator_names(
sub
{
$_
->{is_extra}});
}
sub
experimental_indicator_names {
shift
->_indicator_names(
sub
{
$_
->{is_experimental}});
}
q{Favourite record of the moment:
Jahcoozi: Pure Breed Mongrel}
;