use
5.008001;
our
$VERSION
=
'1.090_102'
;
$VERSION
=
eval
$VERSION
;
sub
get_directory_object {
my
$self
=
shift
;
my
$id
=
shift
;
my
$self_id
=
$self
->get_directory_id();
return
$self
if
(
$id
eq
$self_id
);
my
$return
;
SUBDIRECTORY:
foreach
my
$object
(
$self
->get_child_tags() ) {
next
SUBDIRECTORY
if
not _INSTANCE(
$object
,
'Perl::Dist::WiX::Directory'
);
$return
=
$object
->get_directory_object(
$id
);
return
$return
if
defined
$return
;
}
return
undef
;
}
sub
search_dir {
my
$self
=
shift
;
my
%args
;
if
(
@_
== 1 &&
'HASH'
eq
ref
$_
[0] ) {
%args
= %{
$_
[0] };
}
elsif
(
@_
% 2 == 0 ) {
%args
=
@_
;
}
else
{
}
my
$path_to_find
= _STRING(
$args
{
'path_to_find'
} )
|| PDWiX::Parameter->throw(
parameter
=>
'path_to_find'
,
where
=>
'::Directory->search_dir'
);
my
$descend
=
$args
{descend} || 1;
my
$exact
=
$args
{exact} || 0;
my
$path
=
$self
->get_path();
return
undef
unless
defined
$path
;
if
( (
defined
$path
) && (
$path_to_find
eq
$path
) ) {
return
$self
;
}
return
undef
unless
$descend
;
my
$subset
=
"$path_to_find\\"
=~ m{\A\Q
$path
\E\\}msx;
if
( not
$subset
) {
return
undef
;
}
my
@tags
=
$self
->get_child_tags();
my
$answer
;
TAG:
foreach
my
$tag
(
@tags
) {
next
TAG
unless
$tag
->isa(
'Perl::Dist::WiX::Directory'
);
my
$x
=
ref
$tag
;
my
$y
=
$tag
->get_path();
$answer
=
$tag
->search_dir( \
%args
);
if
(
defined
$answer
) {
return
$answer
;
}
}
return
$exact
?
undef
:
$self
;
}
sub
_add_directory_recursive {
my
$self
=
shift
;
my
$path_to_find
=
shift
;
my
$dir_to_add
=
shift
;
if
(
length
$path_to_find
< 4 ) {
return
undef
;
}
my
$directory
=
$self
->search_dir(
path_to_find
=>
$path_to_find
,
descend
=> 1,
exact
=> 1,
);
if
(
defined
$directory
) {
return
$directory
->add_directory(
parent
=>
$directory
,
name
=>
$dir_to_add
,
);
}
else
{
my
(
$volume
,
$dirs
,
undef
) = splitpath(
$path_to_find
, 1 );
my
@dirs
= splitdir(
$dirs
);
my
$dir_to_add_down
=
pop
@dirs
;
my
$path_to_find_down
= catpath(
$volume
, catdir(
@dirs
),
undef
);
my
$dir
=
$self
->_add_directory_recursive(
$path_to_find_down
,
$dir_to_add_down
);
return
$dir
->add_directory(
name
=>
$dir_to_add
);
}
}
sub
add_directory {
my
$self
=
shift
;
my
$new_dir
= Perl::Dist::WiX::Directory->new(
parent
=>
$self
,
@_
);
$self
->add_child_tag(
$new_dir
);
return
$new_dir
;
}
no
Moose;
__PACKAGE__->meta->make_immutable;
1;