Files
.github
datadog
doc
examples
foreman
hydra
nixos-modules
src
hydra-evaluator
hydra-queue-runner
lib
Hydra
Base
Component
Controller
Event
Helper
AddBuilds.pm
AttributeSet.pm
BuildDiff.pm
CatalystUtils.pm
Email.pm
Escape.pm
Exec.pm
Nix.pm
Model
Plugin
Schema
Script
View
Config.pm
Event.pm
Math.pm
Plugin.pm
PostgresListener.pm
Schema.pm
Task.pm
TaskDispatcher.pm
Hydra.pm
libhydra
root
script
sql
ttf
Makefile.PL
meson.build
t
.editorconfig
.gitignore
.perlcriticrc
COPYING
INSTALL
Procfile
README.md
default.nix
flake.lock
flake.nix
hydra-api.yaml
meson.build
nixos-tests.nix
package.nix
shell.nix
version.txt
hydra/src/lib/Hydra/Helper/AttributeSet.pm

57 lines
990 B
Perl
Raw Normal View History

package Hydra::Helper::AttributeSet;
use strict;
use warnings;
sub new {
my ($self) = @_;
return bless { "paths" => [] }, $self;
}
sub registerValue {
my ($self, $attributePath) = @_;
my @pathParts = splitPath($attributePath);
pop(@pathParts);
if (scalar(@pathParts) == 0) {
return;
}
my $lineage = "";
for my $pathPart (@pathParts) {
$lineage = $self->registerChild($lineage, $pathPart);
}
}
sub registerChild {
my ($self, $parent, $attributePath) = @_;
if ($parent ne "") {
$parent .= "."
}
my $name = $parent . $attributePath;
if (!grep { $_ eq $name} @{$self->{"paths"}}) {
push(@{$self->{"paths"}}, $name);
}
return $name;
}
sub splitPath {
my ($s) = @_;
if ($s eq "") {
return ('')
}
return split(/\./, $s, -1);
}
sub enumerate {
my ($self) = @_;
my @paths = sort { length($a) <=> length($b) } @{$self->{"paths"}};
2021-10-20 12:52:34 -04:00
return @paths;
}
1;