From: Jacob Bachmeyer Date: Fri, 30 Jun 2023 02:57:53 +0000 (-0500) Subject: Add convenience object type for directory names X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=be6e40b57b16dc5b1addb13393b00adbbec76bdd;p=gatekeeper.git Add convenience object type for directory names --- diff --git a/gatekeeper.pl b/gatekeeper.pl index a1efea1..d58a9df 100755 --- a/gatekeeper.pl +++ b/gatekeeper.pl @@ -883,6 +883,56 @@ BEGIN { =back +=head2 Directory Name Objects + +Package C provides a simple directory name object that +stores an array of name components with automatic string conversion to a +POSIX-style relative directory name. + +These objects are used as part of a "parse once" model and refer to +directories within the managed file tree, relative to its base. + +=over + +=cut + +{ + package Local::DirName; + + use overload '""' => sub { File::Spec::Unix->catdir(@{(shift)}) }; + +=item Local::DirName->new $arrayref + +=item Local::DirName->new $directory + +=item Local::DirName->new @directory + +Construct a directory name object. The arguments are any combination of +arrayrefs of directory name elements, strings containing '/' delimiters, +and directory name elements. + +=cut + + sub new { + my $class = shift; + + my @ob; + + for (@_) { + if ('ARRAY' eq ref) { push @ob, @$_ } + elsif (m[/]) { push @ob, File::Spec::Unix->splitdir($_) } + else { push @ob, $_ } + } + + bless \@ob, $class + } + +} + + + +=back + =head2 Exception Definitions and Utilities =cut @@ -2118,7 +2168,7 @@ sub interpret_directive { next; } - $header{directory} = $val; # ok. + $header{directory} = Local::DirName->new(@dirs); # ok. $header{package} = $dirs[0]; # top-level name, no subdir } elsif ($tainted_cmd eq 'filename') { # We use the same filename restrictions as scan_incoming