Callsign/Display/Format.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 64 CC 6 SCAR 26.6
CC
6
Cov
0%
sprint
30.0
format_to_string
6.0
display
2.0
CRAP 14.3
1 # Copyright (C) 2008 Wes Hardaker
2 # License: Same as perl. See the LICENSE file for details.
3 package Ham::Callsign::Display::Format;
4  
5 use Ham::Callsign::Base;
6 use Ham::Callsign;
7 use Data::Dumper;
8 our @ISA = qw(Ham::Callsign::Base);
9  
10 use strict;
11  
12 sub sprint {
13 my ($self, $callsigns, $format) = @_;
14 $format .= "\n" if ($format);
15 $format = $self->{'format'} . "\n" if (!$format && $self->{'format'});
16 if (!$format) {
17 $format = "%{3.3:FromDB}: %{1:operator_class} %{-8.8:thecallsign} %{first_name} %{last_name} => %{qth}\n"
18 }
19  
20 my $output = "";
21  
22 # this allows array refs to be given with multiple calls...
23 foreach my $callsign (@$callsigns) {
24 my $localformat = $self->{$callsign->{'FromDB'} . "format"} . "\n"
25 if (exists($self->{$callsign->{'FromDB'} . "format"}));
26 $output .= format_to_string($localformat || $format, $callsign);
27 }
28 return $output;
29 }
30  
31 sub display {
32 my $self = shift;
33 print $self->sprint(@_);
34 }
35  
36 sub format_to_string {
37 my ($format, $callsign) = @_;
38 my @args;
39  
40 # changes strings like %{NUM:STRING} into sprintf statement arguments
41 while ($format =~ s/\%{(?:(-?[\.\d]+):|)([^\%]+)}/"%" . ($1 || "") . "s"/e) {
42 my $arg;
43 if (defined($callsign->{$2})) {
44 $arg = $callsign->{$2};
45 } else {
46 $arg = "";
47 }
48 push @args, "$arg";
49 }
50 return sprintf($format, @args);
51 }