App-CELL

 view release on metacpan or  search on metacpan

lib/App/CELL/Config.pm  view on Meta::CPAN


=head2 get_param

Get value of config param provided in the argument.

=cut

sub get_param {
    my ( $self, $param ) = @_;
    my ( undef, $file, $line ) = caller;
    die "Bad call to Config.pm \$$param at $file line $line!" if not blessed $self;
    return _retrieve_param( $self->{'CELL_CONFTYPE'}, $param );
}


=head2 get_param_metadata

Routine to provide access not only to the value, but also to the metadata
(file and line number where parameter was defined) associated with a
given parameter.

Takes: parameter name.  Returns: reference to the hash associated with the
given parameter, or undef if no parameter found.

=cut

sub get_param_metadata {
    my ( $self, $param ) = @_;
    my ( undef, $file, $line ) = caller;
    die "Bad call to Config.pm \$$param at $file line $line!" if not blessed $self;
    my $type = $self->{'CELL_CONFTYPE'};
    if ( $type eq 'meta' ) {
        return (exists $meta->{$param})
            ? $meta->{$param}
            : undef;
    } elsif ( $type eq 'core' ) {
        return (exists $core->{$param})
            ? $core->{$param}
            : undef;
    } elsif ( $type eq 'site' ) {
        if (exists $site->{$param}) {
            return $site->{$param};
        } elsif (exists $core->{$param}) {
            return $core->{$param};
        }
    }
    return;
}


=head2 set

Use this function to set new params (meta/core/site) or change existing
ones (meta only). Takes two arguments: parameter name and new value. 
Returns a status object.

=cut

sub set {
    my ( $self, $param, $value ) = @_;
    return App::CELL::Status->not_ok if not blessed $self;
    my %ARGS = (
                    level => 'OK',
                    caller => [ CORE::caller() ],
               );
    if ( $self->{'CELL_CONFTYPE'} eq 'meta' ) {
        if ( exists $meta->{$param} ) {
            %ARGS = (   
                        %ARGS,
                        code => 'CELL_OVERWRITE_META_PARAM',
                        args => [ $param, ( defined( $value ) ? $value : 'undef' ) ],
                    );
            #$log->debug( "Overwriting \$meta->$param with ->$value<-", cell => 1 );
        } else {
            #$log->debug( "Setting new \$meta->$param to ->$value<-", cell => 1 );
        }
        $meta->{$param} = {
                               'File' => (caller)[1],
                               'Line' => (caller)[2],
                               'Value' => $value,
                          };
    } elsif ( $self->{'CELL_CONFTYPE'} eq 'core' ) {
        if ( exists $core->{$param} ) {
            %ARGS = (
                        %ARGS,
                        level => 'ERR',
                        code => 'CELL_PARAM_EXISTS_IMMUTABLE',
                        args => [ 'Core', $param ],
                    );
        } else {
            $core->{$param} = {
                                   'File' => (caller)[1],
                                   'Line' => (caller)[2],
                                   'Value' => $value,
                              };
        }
    } elsif ( $self->{'CELL_CONFTYPE'} eq 'site' ) {
        if ( exists $site->{$param} ) {
            %ARGS = (
                        %ARGS,
                        level => 'ERR',
                        code => 'CELL_PARAM_EXISTS_IMMUTABLE',
                        args => [ 'Site', $param ],
                    );
        } else {
            $site->{$param} = {
                                   'File' => (caller)[1],
                                   'Line' => (caller)[2],
                                   'Value' => $value,
                              };
        }
    }
    return App::CELL::Status->new( %ARGS );
}

# END OF App::CELL::Config MODULE
1;



( run in 0.499 second using v1.01-cache-2.11-cpan-39bf76dae61 )