Config-apiLayers
view release on metacpan or search on metacpan
lib/Config/apiLayers.pm view on Meta::CPAN
}
}
# Add layers up to the given index, with or without data.
# Add a layer with @index and @data, or just @index, or add one more layer without @index
# Add more than one layer by providing the appropriate @index layer number.
# The @data is only set into the last layer.
# @index
# @data
sub add_layer($) {
my $self = shift;
my $args = shift || {};
if (ref $self->{$CXLDATA} ne "ARRAY") {
$self->{$CXLDATA} = [];
}
my $nextLayer = scalar @{$self->{$CXLDATA}};
my $layerNumber = exists $args->{'index'} ? $args->{'index'} : $nextLayer;
for ($nextLayer..$layerNumber) {
push( @{$self->{$CXLDATA}}, {} );
}
if (exists $args->{'data'}) {
$self->config({ data => $args->{'data'} , index => $layerNumber });
}
return (scalar @{$self->{$CXLDATA}} - 1);
}
sub apican(;$) {
my $self = shift;
my $attr_name = shift || undef;
if (defined $attr_name) {
return $self->{$CXLCFG}->{'api'}->{$attr_name} if exists $self->{$CXLCFG}->{'api'}->{$attr_name};
return undef;
} else {
return wantarray ? @{$self->{$CXLCFG}->{'attributes'}} : $self->{$CXLCFG}->{'attributes'};
}
}
sub apicall(;$){
my $self = shift;
my $attr_name = shift || return undef;
if (defined $attr_name) {
my $subref = $self->apican($attr_name);
unshift(@_,$self);
#goto &$subref if defined $subref;
$subref->(@_) if defined $subref;
}
}
#
# Non-Object helper functions
# To be used inside the api functions
#
sub _mendPath(@) {
my @path = @_;
my $path;
foreach my $p (@path) {
next unless defined $p;
if ($path =~ /.+\/$/) {
chop($path);
}
while ($p =~ /.+\/\/$/) {
chop($p);
}
lib/Config/apiLayers.pm view on Meta::CPAN
if ($item =~ /^\//) {
@rootitems = ();
push (@rootitems,$item);
} else {
push (@rootitems,$item);
}
}
return $self->mendPath(@rootitems);
}
sub _dirFileSplit($) {
my $path = shift;
if (-d $path) {
return ($path,undef);
}
my ($baseDir,$fileName) = $path =~ /^(.*\/)([^\/]*)$/;
return @{[$baseDir,$fileName]};
}
sub _dirBase($) {
my $path = shift;
my ($baseDir,$fileName) = _DirFileSplit($path);
$baseDir = './' unless defined $baseDir;
return $baseDir;
}
sub _fileName($) {
my $path = shift;
my ($baseDir,$fileName) = _DirFileSplit($path);
return $fileName;
}
1;
__END__
=pod
( run in 3.807 seconds using v1.01-cache-2.11-cpan-65fba6d93b7 )