EekBoek
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/EB/Report/GenBase.pm view on Meta::CPAN
#! perl -- -*- coding: utf-8 -*-
use utf8;
# Author : Johan Vromans
# Created On : Sat Oct 8 16:40:43 2005
# Last Modified By: Johan Vromans
# Last Modified On: Thu Aug 31 10:01:19 2017
# Update Count : 179
# Status : Unknown, Use with caution!
package main;
our $cfg;
our $dbh;
package EB::Report::GenBase;
use strict;
use EB;
use IO::File;
use EB::Format;
sub new {
my ($class, $opts) = @_;
$class = ref($class) || $class;
my $self = { %$opts };
bless $self => $class;
}
# API.
sub _oops { warn("?Package ".ref($_[0])." did not implement '$_[1]' method\n") }
sub start { shift->_oops('start') }
sub outline { shift->_oops('outline') }
sub finish { shift->_oops('finish') }
# Class methods
sub backend {
my (undef, $self, $opts) = @_;
my %extmap = ( txt => "text", htm => "html" );
my $gen;
# Short options, like --html.
for ( qw(html csv text) ) {
$gen = $_ if $opts->{$_};
}
# Override by explicit --gen-XXX option(s).
foreach ( keys(%$opts) ) {
next unless /^gen-(.*)$/;
$gen = $1;
}
# Override by explicit --generate option(s).
$gen = $opts->{generate} if $opts->{generate};
# Infer from filename extension.
my $t;
if ( !defined($gen) && ($t = $opts->{output}) && $t =~ /\.([^.]+)$/ ) {
my $ext = lc($1);
$ext = $extmap{$ext} || $ext;
$gen = $ext;
}
# Fallback to text.
$gen ||= "text";
# Build class and package name. Last chance to override...
my $class = $opts->{backend} || (ref($self)||$self) . "::" . ucfirst($gen);
my $pkg = $class;
$pkg =~ s;::;/;g;;
$pkg .= ".pm";
# Try to load backend. Gives user the opportunity to override.
eval {
local $SIG{__WARN__};
local $SIG{__DIE__};
require $pkg;
} unless $ENV{AUTOMATED_TESTING};
if ( ! _loaded($class) ) {
my $err = $@;
if ( $err =~ /^can't locate /i ) {
$err = _T("De uitvoer-backend kon niet worden gevonden");
}
die("?".__x("Uitvoer in de vorm {gen} is niet mogelijk: {reason}",
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.400 second using v1.00-cache-2.02-grep-82fe00e-cpan-b63e86051f13 )