Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision a93b3b64

Von Moritz Bunkus vor fast 14 Jahren hinzugefügt

  • ID a93b3b648ec14f94c87176bb8d174da005446d97
  • Vorgänger 65bc835d
  • Nachfolger a5ba22d2

Hilfsfunktionen zum Mappen von Tabellennamen auf Paketnamen und umgekehrt

Conflicts:

SL/DB/Helper/Mappings.pm

Unterschiede anzeigen:

SL/DB/Helper/Mappings.pm
3 3
use utf8;
4 4
use strict;
5 5

  
6
require Exporter;
7
our @ISA       = qw(Exporter);
8
our @EXPORT_OK = qw(get_table_for_package get_package_for_table get_package_names);
9

  
6 10
# these will not be managed as Rose::DB models, because they are not normalized,
7 11
# significant changes are needed to get them done, or they were done by CRM.
8 12
my @lxoffice_blacklist_permanent = qw(
......
90 94
  vendortax                      => 'vendor_tax',
91 95
);
92 96

  
97
my (%lxoffice_tables_to_packages, %lxoffice_tables_to_manager_packages, %lxoffice_packages_to_tables);
98

  
93 99
sub get_blacklist {
94 100
  return LXOFFICE => \@lxoffice_blacklist;
95 101
}
......
98 104
  return LXOFFICE => \%lxoffice_package_names;
99 105
}
100 106

  
107
sub get_package_for_table {
108
  %lxoffice_tables_to_packages = map { ($_ => "SL::DB::" . camelify($lxoffice_package_names{$_})) } keys %lxoffice_package_names
109
    unless %lxoffice_tables_to_packages;
110

  
111
  return $lxoffice_tables_to_packages{ $_[0] };
112
}
113

  
114
sub get_manager_package_for_table {
115
  %lxoffice_tables_to_manager_packages = map { ($_ => "SL::DB::Manager::" . camelify($lxoffice_package_names{$_})) } keys %lxoffice_package_names
116
    unless %lxoffice_tables_to_manager_packages;
117

  
118
  return $lxoffice_tables_to_manager_packages{ $_[0] };
119
}
120

  
121
sub get_table_for_package {
122
  get_package_for_table('dummy') if !%lxoffice_tables_to_packages;
123
  %lxoffice_packages_to_tables = reverse %lxoffice_tables_to_packages unless %lxoffice_packages_to_tables;
124

  
125
  my $package = $_[0] =~ m/^SL::DB::/ ? $_[0] : "SL::DB::" . $_[0];
126
  return $lxoffice_packages_to_tables{ $package };
127
}
128

  
101 129
sub db {
102 130
  my $string = $_[0];
103 131
  my $lookup = $lxoffice_package_names{$_[0]} ||
......
145 173

  
146 174
__END__
147 175

  
176
=encoding utf8
177

  
148 178
=head1 NAME
149 179

  
150 180
SL::DB::Helper::Mappings - Rose Table <-> Model mapping information
......
159 189
L<scripts/rose_auto_create_model.pl> script.  If you add a new table that has
160 190
custom mappings, add it here.
161 191

  
162
=head2 db
192
=head1 FUNCTIONS
163 193

  
164
A special function provided here is E<db>. Without it you'd have to write:
194
=over 4
195

  
196
=item C<db $name>
197

  
198
A special function provided here is C<db>. Without it you'd have to write:
165 199

  
166 200
  my $part = SL::DB::Part->new(id => 1234);
167 201
  my @all_parts = SL::DB::Manager::Part->get_all;
......
177 211
db is written to try to make sense of what you give it, but if all fails, it
178 212
will die with an error.
179 213

  
214
=item C<get_package_for_table $table_name>
215

  
216
Returns the package name for a table name:
217

  
218
  SL::DB::Helpers::Mappings::get_package_for_table('oe')
219
  # SL::DB::Order
220

  
221
=item C<get_manager_package_for_table $table_name>
222

  
223
Returns the manager package name for a table name:
224

  
225
  SL::DB::Helpers::Mappings::get_manager_package_for_table('oe')
226
  # SL::DB::Manager::Order
227

  
228
=item C<get_table_for_package $package_name>
229

  
230
Returns the table name for a package name:
231

  
232
  SL::DB::Helpers::Mappings::get_table_for_package('SL::DB::Order')
233
  # oe
234
  SL::DB::Helpers::Mappings::get_table_for_package('Order')
235
  # oe
236

  
237
=back
238

  
180 239
=head1 BUGS
181 240

  
182 241
nothing yet
......
187 246

  
188 247
=head1 AUTHOR
189 248

  
190
Sven Schöling <s.schoeling@linet-services.de>
249
Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>,
250
Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
191 251

  
192 252
=cut

Auch abrufbar als: Unified diff