From 3e67a3f4c764269b26c2ac8142220101d53db359 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Mon, 4 Jan 2016 17:14:28 +0100 Subject: [PATCH] DefaultManager --- SL/DefaultManager.pm | 102 ++++++++++++++++++++++++++++++++++++ SL/DefaultManager/German.pm | 23 ++++++++ SL/DefaultManager/Swiss.pm | 23 ++++++++ 3 files changed, 148 insertions(+) create mode 100644 SL/DefaultManager.pm create mode 100644 SL/DefaultManager/German.pm create mode 100644 SL/DefaultManager/Swiss.pm diff --git a/SL/DefaultManager.pm b/SL/DefaultManager.pm new file mode 100644 index 000000000..41314ddb3 --- /dev/null +++ b/SL/DefaultManager.pm @@ -0,0 +1,102 @@ +package SL::DefaultManager; + +use strict; + +use SL::Util qw(camelify); +use List::Util qw(first); + +my %manager_cache; + +sub new { + my ($class, @defaults) = @_; + bless [ @defaults ], $class; +} + +sub _managers { + my ($self) = @_; + + map { $self->_get($_) } @$self; +} + +sub _get { + my ($class, $name) = @_; + + return if !$name; + + $manager_cache{$name} ||= do { + die "'$name' doesn't look like a default manager." unless $name =~ /^\w+$/a; + + my $package = 'SL::DefaultManager::' . camelify($name); + + eval "require $package; 1" or die "could not load default manager '$package': $@"; + + $package->new; + } +} + +sub country_modes { + my ($self) = @_; + return ( + 'CH' => 'Switzerland', + 'DE' => 'Germany', + ) +} + +sub AUTOLOAD { + our $AUTOLOAD; + + my ($self, @args) = @_; + + my $method = $AUTOLOAD; + $method =~ s/.*:://; + return if $method eq 'DESTROY'; + + my $manager = first { $_->can($method) } $self->_managers; + + return $manager ? $manager->$method : @args; +} + +1; + +__END__ + +=encoding utf-8 + +=head1 NAME + +SL::DefaultManager - sets of defaults for use outside of clients + +=head1 SYNOPSIS + + # during startup + my $defaults = SL::DefaultManager->new($::lx_office_conf{default_manager}); + + # during tests + my $defaults = SL::DefaultManager->new('swiss'); + + # in consuming code + # will return what the manager provides, or the given value if $defaults does + # not handle dateformat + my $dateformat = $defaults->dateformat('dd.mm.yyyy'); + + # have several default managers for different tasks + # if polled the first defined response will win + my $defaults = SL::DefaultManager->new('swiss', 'mobile', 'point_of_sale'); + +=head1 DESCRIPTION + +TODO + +=head1 FUNCTIONS + +TODO + +=head1 BUGS + +None yet :) + +=head1 AUTHOR + +Sven Schöling Es.schoeling@linet-services.deE + +=cut diff --git a/SL/DefaultManager/German.pm b/SL/DefaultManager/German.pm new file mode 100644 index 000000000..372b8f3a5 --- /dev/null +++ b/SL/DefaultManager/German.pm @@ -0,0 +1,23 @@ +package SL::DefaultManager::German; + +use strict; +use parent qw(Rose::Object); + +# client defaults +sub chart_of_accounts { 'Germany-DATEV-SKR03EU' } +sub accounting_method { 'cash' } +sub inventory_system { 'periodic' } +sub profit_determination { 'income' } +sub currency { 'EUR' } +sub precision { 0.01 } + +# user defaults +sub numberformat { '1.000,00' } +sub dateformat { 'dd.mm.yy' } +sub timeformat { 'hh:mm' } + +# default for login/admin areas +sub country { 'DE' } +sub language { 'de' } + +1; diff --git a/SL/DefaultManager/Swiss.pm b/SL/DefaultManager/Swiss.pm new file mode 100644 index 000000000..78444de68 --- /dev/null +++ b/SL/DefaultManager/Swiss.pm @@ -0,0 +1,23 @@ +package SL::DefaultManager::Swiss; + +use strict; +use parent qw(Rose::Object); + +# client defaults +sub chart_of_accounts { 'Switzerland-deutsch-MWST-2014' } +sub accounting_method { 'accrual' } +sub inventory_system { 'periodic' } +sub profit_determination { 'balance' } +sub currency { 'CHF' } +sub precision { 0.05 } + +# user defaults +sub numberformat { "1'000.00" } +sub dateformat { 'dd.mm.yy' } +sub timeformat { 'hh:mm' } + +# default for login/admin areas +sub country { 'CH' } +sub language { 'de' } + +1; -- 2.20.1