Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 3e67a3f4

Von Sven Schöling vor fast 9 Jahren hinzugefügt

  • ID 3e67a3f4c764269b26c2ac8142220101d53db359
  • Vorgänger 422f2f17
  • Nachfolger 0483b692

DefaultManager

Unterschiede anzeigen:

SL/DefaultManager.pm
1
package SL::DefaultManager;
2

  
3
use strict;
4

  
5
use SL::Util qw(camelify);
6
use List::Util qw(first);
7

  
8
my %manager_cache;
9

  
10
sub new {
11
  my ($class, @defaults) = @_;
12
  bless [ @defaults ], $class;
13
}
14

  
15
sub _managers {
16
  my ($self) = @_;
17

  
18
  map { $self->_get($_) } @$self;
19
}
20

  
21
sub _get {
22
  my ($class, $name) = @_;
23

  
24
  return if !$name;
25

  
26
  $manager_cache{$name} ||= do {
27
    die "'$name' doesn't look like a default manager." unless $name =~ /^\w+$/a;
28

  
29
    my $package = 'SL::DefaultManager::' . camelify($name);
30

  
31
    eval "require $package; 1" or die "could not load default manager '$package': $@";
32

  
33
    $package->new;
34
  }
35
}
36

  
37
sub country_modes {
38
  my ($self) = @_;
39
  return (
40
    'CH' => 'Switzerland',
41
    'DE' => 'Germany',
42
  )
43
}
44

  
45
sub AUTOLOAD {
46
  our $AUTOLOAD;
47

  
48
  my ($self, @args) = @_;
49

  
50
  my $method        =  $AUTOLOAD;
51
  $method           =~ s/.*:://;
52
  return if $method eq 'DESTROY';
53

  
54
  my $manager = first { $_->can($method) } $self->_managers;
55

  
56
  return $manager ? $manager->$method : @args;
57
}
58

  
59
1;
60

  
61
__END__
62

  
63
=encoding utf-8
64

  
65
=head1 NAME
66

  
67
SL::DefaultManager - sets of defaults for use outside of clients
68

  
69
=head1 SYNOPSIS
70

  
71
  # during startup
72
  my $defaults = SL::DefaultManager->new($::lx_office_conf{default_manager});
73

  
74
  # during tests
75
  my $defaults = SL::DefaultManager->new('swiss');
76

  
77
  # in consuming code
78
  # will return what the manager provides, or the given value if $defaults does
79
  # not handle dateformat
80
  my $dateformat = $defaults->dateformat('dd.mm.yyyy');
81

  
82
  # have several default managers for different tasks
83
  # if polled the first defined response will win
84
  my $defaults = SL::DefaultManager->new('swiss', 'mobile', 'point_of_sale');
85

  
86
=head1 DESCRIPTION
87

  
88
TODO
89

  
90
=head1 FUNCTIONS
91

  
92
TODO
93

  
94
=head1 BUGS
95

  
96
None yet :)
97

  
98
=head1 AUTHOR
99

  
100
Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>
101

  
102
=cut
SL/DefaultManager/German.pm
1
package SL::DefaultManager::German;
2

  
3
use strict;
4
use parent qw(Rose::Object);
5

  
6
# client defaults
7
sub chart_of_accounts    { 'Germany-DATEV-SKR03EU' }
8
sub accounting_method    { 'cash' }
9
sub inventory_system     { 'periodic' }
10
sub profit_determination { 'income' }
11
sub currency             { 'EUR' }
12
sub precision            { 0.01 }
13

  
14
# user defaults
15
sub numberformat        { '1.000,00' }
16
sub dateformat          { 'dd.mm.yy' }
17
sub timeformat          { 'hh:mm' }
18

  
19
# default for login/admin areas
20
sub country             { 'DE' }
21
sub language            { 'de' }
22

  
23
1;
SL/DefaultManager/Swiss.pm
1
package SL::DefaultManager::Swiss;
2

  
3
use strict;
4
use parent qw(Rose::Object);
5

  
6
# client defaults
7
sub chart_of_accounts    { 'Switzerland-deutsch-MWST-2014' }
8
sub accounting_method    { 'accrual' }
9
sub inventory_system     { 'periodic' }
10
sub profit_determination { 'balance' }
11
sub currency             { 'CHF' }
12
sub precision            { 0.05 }
13

  
14
# user defaults
15
sub numberformat        { "1'000.00" }
16
sub dateformat          { 'dd.mm.yy' }
17
sub timeformat          { 'hh:mm' }
18

  
19
# default for login/admin areas
20
sub country             { 'CH' }
21
sub language            { 'de' }
22

  
23
1;

Auch abrufbar als: Unified diff