Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 3b2c40d9

Von Tamino Steinert vor etwa 1 Jahr hinzugefügt

  • ID 3b2c40d98c3750937fdb5d765e3d7e28a15392e0
  • Vorgänger 7d7fa7a2
  • Nachfolger 2bef2250

Model::Record: Helferfunktion für Typ zu Klasse von Record Objekten

Unterschiede anzeigen:

SL/DB/Helper/Record.pm
1
package SL::DB::Helper::Record;
2

  
3
use strict;
4
use warnings;
5
use Carp;
6
use Exporter qw(import);
7
use SL::DB::Order::TypeData;
8
use SL::DB::DeliveryOrder::TypeData;
9
use SL::DB::Reclamation::TypeData;
10

  
11
my @export_subs = qw(get_object_name_from_type get_class_from_type);
12

  
13
our @EXPORT_OK = (@export_subs);
14
our %EXPORT_TAGS = (subs => \@export_subs);
15

  
16
my %type_to_object_name = ();
17
$type_to_object_name{$_} = 'Order'         for (@{(SL::DB::Order::TypeData::valid_types)});
18
$type_to_object_name{$_} = 'DeliveryOrder' for (@{(SL::DB::DeliveryOrder::TypeData::valid_types)});
19
$type_to_object_name{$_} = 'Reclamation'   for (@{(SL::DB::Reclamation::TypeData::valid_types)});
20
# TODO: rewrite when invoice type data is available
21
$type_to_object_name{invoice}                     = 'Invoice';
22
$type_to_object_name{invoice_for_advance_payment} = 'Invoice';
23
$type_to_object_name{final_invoice}               = 'Invoice';
24
$type_to_object_name{credit_note}                 = 'Invoice';
25
$type_to_object_name{purchase_invoice}            = 'PurchaseInvoice';
26

  
27
sub get_object_name_from_type {
28
  my ($type) = @_;
29
  return $type_to_object_name{$type} // croak "invalid type '$type'";
30
}
31

  
32
sub get_class_from_type {
33
  my ($type) = @_;
34
  return 'SL::DB::' . get_object_name_from_type($type);
35
}
36

  
37
1;
38

  
39
__END__
40

  
41
=encoding utf8
42

  
43
=head1 NAME
44

  
45
SL::DB::Helper::Record - Helper methods for record objects
46

  
47
=head1 SYNOPSIS
48

  
49
  use SL::DB::Helper::Record;
50

  
51
=head1 DESCRIPTION
52

  
53
This modul includes helper methods for the handling of record object.
54

  
55
=head1 FUNCTIONS
56

  
57
=over 4
58

  
59
=item C<get_object_name_from_type $type>
60

  
61
Returns the name string for corresponding record type:
62

  
63
  SL::DB::Helper::Record::get_class_from_type('sales_order');
64
  # Order
65

  
66
=item C<get_class_from_type $type>
67

  
68
Returns the class string for corresponding record type:
69

  
70
  SL::DB::Helper::Record::get_class_from_type('sales_order');
71
  # SL::DB::Order
72

  
73
=back
74

  
75
=head1 BUGS
76

  
77
nothing yet
78

  
79
=head1 AUTHOR
80

  
81
Tamino Steinert E<lt>tamino.steinert@tamino.stE<gt>
82

  
83
=cut

Auch abrufbar als: Unified diff