1 package SL::DB::Printer;
 
   7 use SL::DB::MetaSetup::Printer;
 
   8 use SL::DB::Manager::Printer;
 
   9 use SL::DB::Helper::Util;
 
  11 __PACKAGE__->meta->initialize;
 
  14   goto &printer_description;
 
  21   push @errors, $::locale->text('The description is missing.')    if !$self->printer_description;
 
  22   push @errors, $::locale->text('The command is missing.')        if !$self->printer_command;
 
  23   push @errors, $::locale->text('The description is not unique.') if !SL::DB::Helper::Util::is_unique($self, 'printer_description');
 
  29   my ($self, %params) = @_;
 
  31   croak "Need either a 'content' or a 'file_name' parameter" if !defined($params{content}) && !$params{file_name};
 
  33   my $copies  = $params{copies} || 1;
 
  34   my $command = SL::Template::create(type => 'ShellCommand', form => Form->new(''))->parse($self->printer_command);
 
  35   my $content = $params{content} // scalar(File::Slurp::read_file($params{file_name}));
 
  38     open my $out, '|-', $command or die $!;
 
  54 SL::DB::Printer - Rose model for database table printers
 
  58   my $printer = SL::DB::Printer->new(id => 4711)->load;
 
  59   $printer->print_document(
 
  61     file_name => '/path/to/file.pdf',
 
  68 =item C<print_document %params>
 
  70 Prints a document by spawning the external command stored in
 
  71 C<$self-E<gt>printer_command> and sending content to it.
 
  73 The caller must provide either the content to send to the printer
 
  74 (parameter C<content>) or a name to a file whose content is sent
 
  75 verbatim (parameter C<file_name>).
 
  77 An optional parameter C<copies> can be given to specify the number of
 
  78 copies to print. This is done by invoking the print command multiple
 
  79 times. The number of copies defaults to 1.
 
  89 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>