File Coverage

blib/lib/BBDB/Export/MailAliases.pm
Criterion Covered Total %
statement 27 34 79.4
branch 9 20 45.0
condition 1 3 33.3
subroutine 5 5 100.0
pod 2 2 100.0
total 44 64 68.7


line stmt bran cond sub pod time code
1             package BBDB::Export::MailAliases;
2 1     1   684 use strict;
  1         2  
  1         34  
3 1     1   5 use warnings;
  1         2  
  1         50  
4              
5             our $VERSION = '0.015';
6              
7              
8             our @ISA = qw(BBDB::Export);
9              
10 1     1   5 use Data::Dumper;
  1         1  
  1         419  
11              
12             #
13             #_* process_record
14             #
15              
16             sub process_record
17             {
18 7     7 1 11 my ( $self, $record ) = @_;
19              
20 7 50       12 return unless ( $record );
21 7 50       19 return unless ( $record->{'full'} );
22 7 100       23 return unless ( $record->{'net'} );
23              
24 2         5 my $email = $record->{'net'}->[0];
25 2         4 my $full = $record->{'full'};
26              
27             # determine nick
28 2         3 my $nick;
29              
30 2 50 33     17 if ( $record->{'nick'} )
    50          
    0          
    0          
31             {
32             # use the first nick in the list
33 0         0 $nick = ( split( /,/, $record->{'nick'} ) )[0];
34             }
35             elsif ( $record->{'first'} && $record->{'last'} )
36             {
37             # build nick of first name and first char of last name
38 2         6 $nick = $record->{'first'};
39 2         8 $nick =~ s|\s.*$||;
40 2         9 $nick .= substr( $record->{'last'}, 0, 1 );
41             }
42             elsif ( $record->{'last'} )
43             {
44             # use last name for nick
45 0         0 $nick = $record->{'last'}
46             }
47             elsif ( $record->{'first'} )
48             {
49             # use first name for nick
50 0         0 $nick = $record->{'first'};
51             }
52              
53             # acceptable characters
54 2         7 $nick =~ tr/a-zA-Z//cd;
55              
56             # lower case the nick
57 2         4 $nick = lc( $nick );
58              
59 2         11 return qq(alias $nick "$full" <$email>\n);
60             }
61              
62             #
63             #_* post_processing
64             #
65              
66             sub post_processing
67             {
68 7     7 1 10 my ( $self, $output ) = @_;
69              
70 7 100       18 return unless $output;
71              
72 2         5 my $outfile = $self->{'data'}->{'output_file'};
73 2 50       8 return unless $outfile;
74              
75 0 0         open ( my $out_fh, ">", $outfile ) or die "Unable to create $outfile";
76 0           print $out_fh $output;
77 0           close $out_fh;
78              
79 0           $self->info( "Exported mail_aliases data to $outfile" );
80             }
81              
82             1;
83              
84