CGI-Snapp
view release on metacpan or search on metacpan
lib/CGI/Snapp.pm view on Meta::CPAN
croak "Error: Invalid header type '$option'. Must be one of: " . join(', ', sort keys %valid) . "\n" if (! $valid{$option});
$self -> _header_type($option);
}
return $self -> _header_type;
} # End of header_type.
# --------------------------------------------------
sub log
{
my($self, $level, $s) = @_;
$level ||= 'info';
$s ||= '';
# We can't use $self here because add_callback can be called as a class method,
# and logging inside add_callback would then call here without initializing $self
# to be an instance. It would just be the string name of the class calling add_callback.
$myself -> logger -> log($level => $s) if ($myself && $myself -> logger);
} # End of log.
# --------------------------------------------------
sub mode_param
{
my($self, @new_options) = @_;
$self -> log(debug => 'mode_param(...)');
my($mode_source);
if (@new_options)
{
my($ref) = ref $new_options[0];
if ( ($#new_options == 0) && ($ref !~ /(?:ARRAY|HASH)/) )
{
$mode_source = $new_options[0];
}
else
{
my(%new_options) = $ref eq 'HASH' ? %{$new_options[0]}
: $ref eq 'ARRAY' ? @{$new_options[0]}
: scalar(@new_options) % 2 == 0 ? @new_options
: croak "Error: Odd number of parameters passed to mode_param()\n";
# We need defined in case someone uses a run mode of 0.
$mode_source = defined($new_options{param}) ? $new_options{param} : '';
my($index) = $new_options{path_info};
my($path_info) = $self -> query -> path_info;
if ($index && $path_info)
{
$index -= 1 if ($index > 0);
$path_info =~ s!^/!!;
$path_info = (split m|/|, $path_info)[$index] || '';
$mode_source = length $index ? {run_mode => $path_info} : $mode_source;
}
}
$self -> _run_mode_source($mode_source);
}
else
{
$mode_source = $self -> _run_mode_source;
}
return $mode_source;
} # End of mode_param.
# --------------------------------------------------
sub new_hook
{
my($self, $hook) = @_;
croak "Error: Can't use undef as a hook name\n" if (! defined $hook);
$hook = lc $hook;
$self -> log(debug => "new_hook($hook)");
$class_callbacks{$hook} ||= {};
return 1;
} # End of new_hook.
# --------------------------------------------------
sub param
{
my($self, @params) = @_;
$self -> log(debug => 'param(...)');
my(%old) = %{$self -> _params};
my($returnz);
my($value);
if (@params)
{
my(%new);
if (ref $params[0] eq 'HASH')
{
%new = %{$params[0]};
}
elsif (ref $params[0] eq 'ARRAY')
{
%new = @{$params[0]};
}
elsif (scalar @params % 2 == 0)
{
( run in 5.024 seconds using v1.01-cache-2.11-cpan-483215c6ad5 )