CIPP
view release on metacpan or search on metacpan
lib/CIPP/Runtime/NewSpirit.pm view on Meta::CPAN
require Encode;
require Locale::Messages;
require POSIX;
foreach my $module ( values %{$conf} ) {
my $domain = $module->{domain};
Locale::Messages::bindtextdomain($domain, $l10n_dir);
Locale::Messages::bind_textdomain_codeset($domain, "utf-8");
Locale::Messages::bind_textdomain_filter($domain, sub {
Encode::_utf8_on($_[0]);$_[0]
});
}
1;
}
package CIPP::Runtime::NewSpirit::Request;
use vars qw ( @ISA );
use strict;
use Carp;
use CIPP::Runtime::Request;
@ISA = qw ( CIPP::Runtime::Request );
sub get_mime_type { shift->{mime_type} }
sub set_mime_type { shift->{mime_type} = $_[1] }
sub new {
my $type = shift;
my %par = @_;
my ($mime_type) = @par{'mime_type'};
my $self = bless $type->SUPER::new(@_), $type;
$self->set_mime_type ($mime_type);
if ( $self->get_project_handle->get_utf8 and $] >= 5.008 ) {
binmode STDOUT, ":utf8";
} else {
binmode STDOUT;
}
return $self;
}
sub init {
my $self = shift;
# determine name of the script
# ($0 is messed up with SpeedyCGI, so fallback to
# SCRIPT_FILENAME if no .cgi in there)
my $script_name = ( $0 =~ /\.cgi$/ ? $0 : undef ) ||
$ENV{SCRIPT_FILENAME};
$self->set_script_name($script_name);
# change to program dir
$script_name =~ m!^(.*)[/\\][^/\\]+$!;
chdir $1 if $1;
# set $CIPP::ee (End of Element, XHTML conformity)
$CIPP::ee = $self->get_xhtml ? " /" : "";
1;
}
sub print_http_header {
my $self = shift;
my $mime_type = $self->get_mime_type;
if ( $mime_type =~ m!text/html!i &&
$mime_type !~ /charset=/i &&
$self->get_utf8 ) {
$mime_type = "text/html; charset=utf-8";
}
if ( $mime_type ne 'cipp/dynamic' ) {
$self->get_http_header->{'content-type'} = $mime_type;
$self->SUPER::print_http_header(@_);
}
1;
}
sub get_db_config {
my $self = shift;
my %par = @_;
my ($db) = @par{'db'};
my $filename = $self->get_project_handle->get_config_dir."/$db.db-conf";
if ( not -e $filename ) {
foreach my $config_dir ( map { $_."/config" }
@{$self->get_project_handle
->get_add_prod_dirs} ) {
$filename = "$config_dir/$db.db-conf";
last if -e $filename;
}
# set full_path to this project's config dir, if not
# found. This produces an error message which belongs
# to this project.
$filename = $self->get_config_dir."/$db.db-conf" if not -e $filename;
}
my $config = do $filename;
if ( not ref $config ) {
croak "Database config file '$filename' not found or wrong format.";
}
return $config;
}
sub resolve_filename {
my $self = shift;
my %par = @_;
my ($name, $throw, $type) = @par{'name','throw','type'};
( run in 2.011 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )