]> wagnertech.de Git - mfinanz.git/blobdiff - SL/DB/Helper/LinkedRecords.pm
LinkedRecords-Helfer: Dokumentationsupdate
[mfinanz.git] / SL / DB / Helper / LinkedRecords.pm
index 99cb3ed7b504a87e8df3d85f090081fc2622be97..95b5e7037c27824960366c7051c10abc3101277e 100644 (file)
@@ -1,4 +1,4 @@
-package SL::DB::Helpers::LinkedRecords;
+package SL::DB::Helper::LinkedRecords;
 
 use strict;
 
@@ -9,7 +9,7 @@ our @EXPORT = qw(linked_records link_to_record);
 use Carp;
 use Sort::Naturally;
 
-use SL::DB::Helpers::Mappings;
+use SL::DB::Helper::Mappings;
 use SL::DB::RecordLink;
 
 sub linked_records {
@@ -19,14 +19,14 @@ sub linked_records {
                           dir => delete($params{sort_dir}) );
   my $filter          =  delete $params{filter};
 
-  my $records         = linked_records_implementation($self, %params);
+  my $records         = _linked_records_implementation($self, %params);
   $records            = filter_linked_records($self, $filter, @{ $records })                       if $filter;
   $records            = sort_linked_records($self, $sort_spec{by}, $sort_spec{dir}, @{ $records }) if $sort_spec{by};
 
   return $records;
 }
 
-sub linked_records_implementation {
+sub _linked_records_implementation {
   my $self     = shift;
   my %params   = @_;
 
@@ -37,8 +37,8 @@ sub linked_records_implementation {
     my %from_to    = ( from => delete($params{from}) || $both,
                        to   => delete($params{to})   || $both);
 
-    my @records    = (@{ linked_records_implementation($self, %params, direction => 'from', from => $from_to{from}) },
-                      @{ linked_records_implementation($self, %params, direction => 'to',   to   => $from_to{to}  ) });
+    my @records    = (@{ _linked_records_implementation($self, %params, direction => 'from', from => $from_to{from}) },
+                      @{ _linked_records_implementation($self, %params, direction => 'to',   to   => $from_to{to}  ) });
 
     my %record_map = map { ( ref($_) . $_->id => $_ ) } @records;
 
@@ -47,14 +47,14 @@ sub linked_records_implementation {
 
   my $myself   = $wanted eq 'from' ? 'to' : $wanted eq 'to' ? 'from' : croak("Invalid parameter `direction'");
 
-  my $my_table = SL::DB::Helpers::Mappings::get_table_for_package(ref($self));
+  my $my_table = SL::DB::Helper::Mappings::get_table_for_package(ref($self));
 
   my @query    = ( "${myself}_table" => $my_table,
                    "${myself}_id"    => $self->id );
 
   if ($params{$wanted}) {
     my $wanted_classes = ref($params{$wanted}) eq 'ARRAY' ? $params{$wanted} : [ $params{$wanted} ];
-    my $wanted_tables  = [ map { SL::DB::Helpers::Mappings::get_table_for_package($_) || croak("Invalid parameter `${wanted}'") } @{ $wanted_classes } ];
+    my $wanted_tables  = [ map { SL::DB::Helper::Mappings::get_table_for_package($_) || croak("Invalid parameter `${wanted}'") } @{ $wanted_classes } ];
     push @query, ("${wanted}_table" => $wanted_tables);
   }
 
@@ -67,8 +67,8 @@ sub linked_records_implementation {
   @query               = ref($params{query}) eq 'ARRAY' ? @{ $params{query} } : ();
 
   foreach my $link (@{ $links }) {
-    my $manager_class = SL::DB::Helpers::Mappings::get_manager_package_for_table($link->$sub_wanted_table);
-    my $object_class  = SL::DB::Helpers::Mappings::get_package_for_table($link->$sub_wanted_table);
+    my $manager_class = SL::DB::Helper::Mappings::get_manager_package_for_table($link->$sub_wanted_table);
+    my $object_class  = SL::DB::Helper::Mappings::get_package_for_table($link->$sub_wanted_table);
     eval "require " . $object_class . "; 1;";
     push @{ $records }, @{ $manager_class->get_all(query => [ id => $link->$sub_wanted_id, @query ]) };
   }
@@ -194,7 +194,7 @@ __END__
 
 =head1 NAME
 
-SL::DB::Helpers::LinkedRecords - Mixin for retrieving linked records via the table C<record_links>
+SL::DB::Helper::LinkedRecords - Mixin for retrieving linked records via the table C<record_links>
 
 =head1 FUNCTIONS
 
@@ -210,23 +210,23 @@ from C<$self> (for C<direction> = C<from>). For C<direction = both>
 all records linked from or to C<$self> are returned.
 
 The optional parameter C<from> or C<to> (same as C<direction>)
-contains the package names of Rose models for table limitation. It can
-be a single model name as a single scalar or multiple model names in
-an array reference in which case all links matching any of the model
-names will be returned.
+contains the package names of Rose models for table limitation (the
+prefix C<SL::DB::> is optional). It can be a single model name as a
+single scalar or multiple model names in an array reference in which
+case all links matching any of the model names will be returned.
 
 If you only need invoices created from an order C<$order> then the
 call could look like this:
 
   my $invoices = $order->linked_records(direction => 'to',
-                                        to        => 'SL::DB::Invoice');
+                                        to        => 'Invoice');
 
 The optional parameter C<query> can be used to limit the records
 returned. The following call limits the earlier example to invoices
 created today:
 
   my $invoices = $order->linked_records(direction => 'to',
-                                        to        => 'SL::DB::Invoice',
+                                        to        => 'Invoice',
                                         query     => [ transdate => DateTime->today_local ]);
 
 The optional parameters C<$params{sort_by}> and C<$params{sort_dir}>