our
$VERSION
=
'1.22'
;
my
$test
= Test::Builder->new();
my
$test_bool
= 1;
my
$plan
= 0;
my
$counter
= 0;
sub
import
{
my
$self
=
shift
;
my
$caller
=
caller
;
my
%plan
=
@_
;
for
my
$func
(
qw( ok_manifest )
) {
no
strict
'refs'
;
*{
$caller
.
"::"
.
$func
} = \
&$func
;
}
$test
->exported_to(
$caller
);
$test
->plan(
%plan
);
$plan
= 1
if
(
exists
$plan
{tests});
}
sub
ok_manifest{
my
(
$hashref
,
$msg
) =
@_
;
$test
->plan(
tests
=> 1)
unless
$plan
;
my
$is_hashref
= 1;
$is_hashref
= 0
unless
ref
(
$hashref
);
$msg
=
$hashref
unless
$is_hashref
;
my
$bool
= 1;
my
$home
= Cwd::realpath( dirname(File::Spec->rel2abs($0)) .
'/..'
);
my
$manifest
= Cwd::realpath(
$home
.
'/MANIFEST'
);
my
$skip
;
eval
{
$skip
= Cwd::realpath(
$home
.
'/MANIFEST.SKIP'
); 1; };
my
@missing_files
= ();
my
@files_plus
= ();
my
$arref
= [
'/blib'
,
'/_build'
];
my
$filter
=
$is_hashref
&&
$hashref
->{filter} ?
$hashref
->{filter} : [];
my
$comb
=
$is_hashref
&&
$hashref
->{bool} &&
$hashref
->{bool} =~ m/^and$/i ?
'and'
:
'or'
;
push
@$arref
, @{
$hashref
->{exclude}}
if
$is_hashref
and
exists
$hashref
->{exclude} and
ref
(
$hashref
->{exclude}) eq
'ARRAY'
;
for
(
@$arref
){
croak
'path in excluded array must be "absolute"'
unless
m!^/!;
my
$path
=
$home
.
$_
;
next
unless
-e
$path
;
$_
= Cwd::realpath(
$path
);
}
@$arref
=
grep
{
defined
}
@$arref
;
unless
(
open
my
$fh
,
'<'
,
$manifest
){
$bool
= 0;
$msg
=
"can't open $manifest"
;
}
else
{
{
my
$files_in_skip
= _read_skip(
$skip
, \
$msg
, \
$bool
);
last
unless
$files_in_skip
;
my
@files
;
while
(
my
$fh_line
= <
$fh
> ){
if
(
$fh_line
=~ /^\s*([^\s
push
@files
, $1;
}
}
close
$fh
;
chomp
@files
;
{
local
$/ =
"\r"
;
chomp
@files
;
}
for
my
$tfile
(
@files
){
$tfile
= (
split
(/\s{2,}/,
$tfile
,2))[0];
next
unless
-e
$home
.
'/'
.
$tfile
;
$tfile
= Cwd::realpath(
$home
.
'/'
.
$tfile
);
}
my
(
@dir_files
,
%files_hash
,
%excluded
);
@files_hash
{
@files
} = ();
find({
no_chdir
=> 1,
wanted
=>
sub
{
my
$file
=
$File::Find::name
;
my
$is_excluded
= _is_excluded(
$file
,
$arref
,
$filter
,
$comb
,
$files_in_skip
,
$home
,
);
push
(
@dir_files
,Cwd::realpath(
$file
))
if
-f
$file
and !
$is_excluded
;
$excluded
{
$file
} = 1
if
-f
$file
and
$is_excluded
}
},
$home
);
SFILE:
for
my
$file
(
@dir_files
){
for
my
$check
(
@files
){
if
(
$file
eq
$check
){
delete
$files_hash
{
$check
};
next
SFILE;
}
}
push
(
@missing_files
,
$file
);
$bool
= 0;
}
delete
$files_hash
{
$_
}
for
keys
%excluded
;
@files_plus
=
sort
keys
%files_hash
;
$bool
= 0
if
scalar
@files_plus
> 0;
}
}
my
$diag
=
'The following files are not named in the MANIFEST file: '
.
join
(
', '
,
@missing_files
);
my
$plus
=
'The following files are not part of distro but named in the MANIFEST file: '
.
join
(
', '
,
@files_plus
);
$test
->is_num(
$test_bool
,
$bool
,
$msg
);
$test
->diag(
$diag
)
if
scalar
@missing_files
>= 1 and
$test_bool
== 1;
$test
->diag(
$plus
)
if
scalar
@files_plus
>= 1 and
$test_bool
== 1;
}
sub
_not_ok_manifest{
$test_bool
= 0;
ok_manifest(
@_
);
$test_bool
= 1;
}
sub
_is_excluded{
my
(
$file
,
$dirref
,
$filter
,
$bool
,
$files_in_skip
,
$home
) =
@_
;
my
@excluded_files
=
qw(pm_to_blib Makefile META.yml Build pod2htmd.tmp
pod2htmi.tmp Build.bat .cvsignore)
;
if
(
$files_in_skip
and
'ARRAY'
eq
ref
$files_in_skip
) {
(
my
$local_file
=
$file
) =~ s{\Q
$home
\E/?}{};
for
my
$rx
( @{
$files_in_skip
} ) {
my
$regex
=
qr/$rx/
;
return
1
if
$local_file
=~
$regex
;
}
}
my
@matches
=
grep
{
$file
=~ /
$_
$/ }
@excluded_files
;
if
(
$bool
eq
'or'
){
push
@matches
,
$file
if
grep
{
ref
(
$_
) and
ref
(
$_
) eq
'Regexp'
and
$file
=~ /
$_
/}
@$filter
;
push
@matches
,
$file
if
grep
{
$file
=~ /^\Q
$_
\E/}
@$dirref
;
}
else
{
if
(
grep
{
$file
=~ /
$_
/ and
ref
(
$_
) and
ref
(
$_
) eq
'Regexp'
}
@$filter
and
grep
{
$file
=~ /^\Q
$_
\E/ and not
ref
(
$_
)}
@$dirref
){
push
@matches
,
$file
;
}
}
return
scalar
@matches
;
}
sub
_read_skip {
my
(
$skip
,
$msg
,
$bool
) =
@_
;
return
[]
unless
$skip
and -e
$skip
;
my
@files
;
if
( -e
$skip
and not
open
my
$skip_fh
,
'<'
,
$skip
) {
$$bool
= 0;
$$msg
=
"can't open $skip"
;
return
;
}
else
{
while
(
my
$line
= <
$skip_fh
> ) {
chomp
$line
;
next
if
$line
=~ m{ \A \s* \
my
(
$file
,
$comment
);
if
((
$file
,
$comment
) =
$line
=~ /^
'(\\[\\'
]|.+)+'\s*(.*)/) {
$file
=~ s/\\([\\'])/$1/g;
}
else
{
(
$file
,
$comment
) =
$line
=~ /^(\S+)\s*(.*)/;
}
next
unless
$file
;
push
@files
,
$file
;
}
}
return
\
@files
;
}
1;