| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #!/usr/bin/perl | 
| 2 | 1 |  |  | 1 |  | 1100 | use strict; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 47 |  | 
| 3 | 1 |  |  | 1 |  | 5 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 66 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | package App::Addex::AddressBook::Abook; | 
| 6 |  |  |  |  |  |  | { | 
| 7 |  |  |  |  |  |  | $App::Addex::AddressBook::Abook::VERSION = '0.008'; | 
| 8 |  |  |  |  |  |  | } | 
| 9 | 1 |  |  | 1 |  | 6 | use base qw(App::Addex::AddressBook); | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 614 |  | 
| 10 |  |  |  |  |  |  | # ABSTRACT: use the "abook" program as the addex source | 
| 11 |  |  |  |  |  |  |  | 
| 12 | 1 |  |  | 1 |  | 527 | use App::Addex::Entry::EmailAddress; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | use File::HomeDir; | 
| 15 |  |  |  |  |  |  | use File::Spec; | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | { | 
| 18 |  |  |  |  |  |  | package | 
| 19 |  |  |  |  |  |  | App::Addex::AddressBook::Abook::INI::Reader; | 
| 20 |  |  |  |  |  |  | use Config::INI::Reader; # probably already loaded, but... -- rjbs, 2007-05-09 | 
| 21 |  |  |  |  |  |  | BEGIN { our @ISA = 'Config::INI::Reader' } | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | sub can_ignore { | 
| 24 |  |  |  |  |  |  | my ($self, $line) = @_; | 
| 25 |  |  |  |  |  |  | return $line =~ /\A\s*(?:[;#]|$)/ ? 1 : 0; | 
| 26 |  |  |  |  |  |  | } | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | sub preprocess_line { | 
| 29 |  |  |  |  |  |  | my ($self, $line) = @_; | 
| 30 |  |  |  |  |  |  | ${$line} =~ s/\s+[;#].*$//g; | 
| 31 |  |  |  |  |  |  | } | 
| 32 |  |  |  |  |  |  | } | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | sub new { | 
| 36 |  |  |  |  |  |  | my ($class, $arg) = @_; | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | my $self = bless {} => $class; | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | $arg->{filename} ||= File::Spec->catfile( | 
| 41 |  |  |  |  |  |  | File::HomeDir->my_home, | 
| 42 |  |  |  |  |  |  | '.abook', | 
| 43 |  |  |  |  |  |  | 'addressbook', | 
| 44 |  |  |  |  |  |  | ); | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | eval { | 
| 47 |  |  |  |  |  |  | $self->{config} = App::Addex::AddressBook::Abook::INI::Reader | 
| 48 |  |  |  |  |  |  | ->read_file($arg->{filename}); | 
| 49 |  |  |  |  |  |  | }; | 
| 50 |  |  |  |  |  |  | Carp::croak "couldn't read abook address book file: $@" if $@; | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | $self->{$_} = $arg->{$_} for qw(sig_field folder_field); | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | return $self; | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | sub _entrify { | 
| 58 |  |  |  |  |  |  | my ($self, $person) = @_; | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | return unless my @emails = | 
| 61 |  |  |  |  |  |  | map { App::Addex::Entry::EmailAddress->new($_) } | 
| 62 |  |  |  |  |  |  | split /\s*,\s*/, ($person->{email}||''); | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | my %field; | 
| 65 |  |  |  |  |  |  | $field{ $_ } = $person->{ $self->{"$_\_field"} } for qw(sig folder); | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | return App::Addex::Entry->new({ | 
| 68 |  |  |  |  |  |  | name   => $person->{name}, | 
| 69 |  |  |  |  |  |  | nick   => $person->{nick}, | 
| 70 |  |  |  |  |  |  | emails => \@emails, | 
| 71 |  |  |  |  |  |  | fields => \%field, | 
| 72 |  |  |  |  |  |  | }); | 
| 73 |  |  |  |  |  |  | } | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | sub entries { | 
| 76 |  |  |  |  |  |  | my ($self) = @_; | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | my @entries = map { $self->_entrify($self->{config}{$_}) } | 
| 79 |  |  |  |  |  |  | sort grep { /\A\d+\z/ } | 
| 80 |  |  |  |  |  |  | keys %{ $self->{config} }; | 
| 81 |  |  |  |  |  |  | } | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | 1; | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | __END__ | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | =pod | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | =head1 NAME | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | App::Addex::AddressBook::Abook - use the "abook" program as the addex source | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | =head1 VERSION | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | version 0.008 | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | This module implements the L<App::Addex::AddressBook> interface for the | 
| 100 |  |  |  |  |  |  | Mutt-friendly "abook" program. | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | =head1 CONFIGURATION | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | The following configuration options are valid: | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | filename  - the address book file to read; defaults to ~/.abook/addressbook | 
| 107 |  |  |  |  |  |  | sig_field - the address book entry property that stores the "sig" field | 
| 108 |  |  |  |  |  |  | folder_field - the address book entry property that stores the "sig" field | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | =head1 AUTHOR | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | Ricardo SIGNES <rjbs@cpan.org> | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | This software is copyright (c) 2006 by Ricardo SIGNES. | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | This is free software; you can redistribute it and/or modify it under | 
| 119 |  |  |  |  |  |  | the same terms as the Perl 5 programming language system itself. | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | =cut |