| 1 | 5 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 2 | 5 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | # because tests use open to open a string-ref, and I am not interested in ever | ||||||||||||||||||||
| 5 | # supporting this module on ancient perls -- rjbs, 2007-12-17 | ||||||||||||||||||||
| 6 | 5 | ▶ | use 5.008; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | package App::Addex 0.027; | ||||||||||||||||||||
| 9 | # ABSTRACT: generate mail tool configuration from an address book | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 5 | ▶ | use Carp (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | #pod =head1 DESCRIPTION | ||||||||||||||||||||
| 14 | #pod | ||||||||||||||||||||
| 15 | #pod B<Achtung!> The API to this code may very well change. It is almost certain | ||||||||||||||||||||
| 16 | #pod to be broken into smaller pieces, to support alternate sources of entries, and | ||||||||||||||||||||
| 17 | #pod it might just get plugins. | ||||||||||||||||||||
| 18 | #pod | ||||||||||||||||||||
| 19 | #pod This module iterates through all the entries in an address book and produces | ||||||||||||||||||||
| 20 | #pod configuration file based on the entries in the address book, using configured | ||||||||||||||||||||
| 21 | #pod output plugins. | ||||||||||||||||||||
| 22 | #pod | ||||||||||||||||||||
| 23 | #pod It is meant to be run with the F<addex> command, which is bundled as part of | ||||||||||||||||||||
| 24 | #pod this software distribution. | ||||||||||||||||||||
| 25 | #pod | ||||||||||||||||||||
| 26 | #pod =method new | ||||||||||||||||||||
| 27 | #pod | ||||||||||||||||||||
| 28 | #pod my $addex = App::Addex->new(\%arg); | ||||||||||||||||||||
| 29 | #pod | ||||||||||||||||||||
| 30 | #pod This method returns a new Addex. | ||||||||||||||||||||
| 31 | #pod | ||||||||||||||||||||
| 32 | #pod Valid parameters are: | ||||||||||||||||||||
| 33 | #pod | ||||||||||||||||||||
| 34 | #pod classes - a hashref of plugin/class pairs, described below | ||||||||||||||||||||
| 35 | #pod | ||||||||||||||||||||
| 36 | #pod Valid keys for the F<classes> parameter are: | ||||||||||||||||||||
| 37 | #pod | ||||||||||||||||||||
| 38 | #pod addressbook - the App::Addex::AddressBook subclass to use (required) | ||||||||||||||||||||
| 39 | #pod output - an array of output producers (required) | ||||||||||||||||||||
| 40 | #pod | ||||||||||||||||||||
| 41 | #pod For each class given, an entry in C<%arg> may be given, which will be used to | ||||||||||||||||||||
| 42 | #pod initialize the plugin before use. | ||||||||||||||||||||
| 43 | #pod | ||||||||||||||||||||
| 44 | #pod =cut | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | # sub starting_section_name { 'classes' } | ||||||||||||||||||||
| 47 | 0 | ▶ | sub mvp_multivalue_args { qw(output plugin) } | ||||||||||||||||||
|
Subroutine
mvp_multivalue_args: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 7 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=10 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 50 | 7 | my ($class, $arg) = @_; | |||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 7 | my $self = bless {} => $class; | |||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | # XXX: keep track of seen/unseen classes; carp if some go unused? | ||||||||||||||||||||
| 55 | # -- rjbs, 2007-04-06 | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 7 | for my $core (qw(addressbook)) { | |||||||||||||||||||
| 58 | 7 | ▶ | my $class = $arg->{classes}{$core} | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 59 | or Carp::confess "no $core class provided"; | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 6 | $self->{$core} = $self->_initialize_plugin($class, $arg->{$class}); | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 6 | ▶ | my @output_classes = @{ $arg->{classes}{output} || [] } | ||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$arg->{'classes'}{'output'} || []
MC/DC100%1/1
$arg->{'classes'}{'output'} || []
$arg->{'classes'}{'output'}
Truth table100%2/2
A
A= $arg->{'classes'}{'output'}
| |||||||||||||||||||||
| 65 | or Carp::confess "no output classes provided"; | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 5 | my @output_plugins; | |||||||||||||||||||
| 68 | 5 | for my $class (@output_classes) { | |||||||||||||||||||
| 69 | 5 | push @output_plugins, $self->_initialize_plugin($class, $arg->{$class}); | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | 4 | $self->{output} = \@output_plugins; | |||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 4 | ▶ | my @plugin_classes = @{ $arg->{classes}{plugin} || [] }; | ||||||||||||||||||
|
Condition50%1/2
$arg->{'classes'}{'plugin'} || []
MC/DC0%0/1
$arg->{'classes'}{'plugin'} || []
$arg->{'classes'}{'plugin'}
Truth table50%1/2
A
A= $arg->{'classes'}{'plugin'}
| |||||||||||||||||||||
| 74 | 4 | for my $class (@plugin_classes) { | |||||||||||||||||||
| 75 | 0 | ▶ | eval "require $class" or die; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 76 | 0 | ▶ | $class->import(%{ $arg->{$class} || {} }); | ||||||||||||||||||
|
Condition0%0/2
$arg->{$class} || {}
MC/DC0%0/1
$arg->{$class} || {}
$arg->{$class}
Truth table0%0/2
A
A= $arg->{$class}
| |||||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 4 | return $self; | |||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 0 | ▶ | sub from_sequence { | ||||||||||||||||||
|
Subroutine
from_sequence: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 83 | 0 | my ($class, $seq) = @_; | |||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 0 | my %arg; | |||||||||||||||||||
| 86 | 0 | for my $section ($seq->sections) { | |||||||||||||||||||
| 87 | 0 | $arg{ $section->name } = $section->payload; | |||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 0 | $class->new(\%arg); | |||||||||||||||||||
| 91 | } | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 11 | ▶ | sub _initialize_plugin { | ||||||||||||||||||
|
Subroutine
_initialize_plugin: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 94 | 11 | my ($self, $class, $arg) = @_; | |||||||||||||||||||
| 95 | 11 | ▶ | $arg ||= {}; | ||||||||||||||||||
|
Condition100%2/2
$arg ||= {}
MC/DC100%1/1
$arg ||= {}
$arg
Truth table100%2/2
A
A= $arg
| |||||||||||||||||||||
| 96 | 11 | $arg->{addex} = $self; | |||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | # in most cases, this won't be needed, since the App::Addex::Config will have | ||||||||||||||||||||
| 99 | # loaded plugins as a side effect, but let's be cautious -- rjbs, 2007-05-10 | ||||||||||||||||||||
| 100 | 11 | ▶ | eval "require $class" or die; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | 10 | return $class->new($arg); | |||||||||||||||||||
| 103 | } | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | #pod =method addressbook | ||||||||||||||||||||
| 106 | #pod | ||||||||||||||||||||
| 107 | #pod my $abook = $addex->addressbook; | ||||||||||||||||||||
| 108 | #pod | ||||||||||||||||||||
| 109 | #pod This method returns the App::Addex::AddressBook object. | ||||||||||||||||||||
| 110 | #pod | ||||||||||||||||||||
| 111 | #pod =cut | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 4 | ▶ | sub addressbook { $_[0]->{addressbook} } | ||||||||||||||||||
|
Subroutine
addressbook: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | #pod =method output_plugins | ||||||||||||||||||||
| 116 | #pod | ||||||||||||||||||||
| 117 | #pod This method returns all of the output plugin objects. | ||||||||||||||||||||
| 118 | #pod | ||||||||||||||||||||
| 119 | #pod =cut | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | 28 | ▶ | sub output_plugins { | ||||||||||||||||||
|
Subroutine
output_plugins: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 122 | 28 | my ($self) = @_; | |||||||||||||||||||
| 123 | 28 | return @{ $self->{output} }; | |||||||||||||||||||
| 124 | } | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | #pod =method entries | ||||||||||||||||||||
| 127 | #pod | ||||||||||||||||||||
| 128 | #pod This method returns all the entries to be processed. By default it is | ||||||||||||||||||||
| 129 | #pod delegated to the address book object. This method may change a good bit in the | ||||||||||||||||||||
| 130 | #pod future, as we really want an iterator, not just a list. | ||||||||||||||||||||
| 131 | #pod | ||||||||||||||||||||
| 132 | #pod =cut | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | 4 | ▶ | sub entries { | ||||||||||||||||||
|
Subroutine
entries: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 135 | 4 | my ($self) = @_; | |||||||||||||||||||
| 136 | 4 | return sort { $a->name cmp $b->name } $self->addressbook->entries; | |||||||||||||||||||
| 137 | } | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | #pod =method run | ||||||||||||||||||||
| 140 | #pod | ||||||||||||||||||||
| 141 | #pod App::Addex->new({ ... })->run; | ||||||||||||||||||||
| 142 | #pod | ||||||||||||||||||||
| 143 | #pod This method performs all the work expected of an Addex: it iterates through the | ||||||||||||||||||||
| 144 | #pod entries, invoking the output plugins for each one. | ||||||||||||||||||||
| 145 | #pod | ||||||||||||||||||||
| 146 | #pod =cut | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | 4 | ▶ | sub run { | ||||||||||||||||||
|
Subroutine
run: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||
| 149 | 4 | my ($self) = @_; | |||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | 4 | for my $entry ($self->entries) { | |||||||||||||||||||
| 152 | 24 | for my $plugin ($self->output_plugins) { | |||||||||||||||||||
| 153 | 24 | $plugin->process_entry($self, $entry); | |||||||||||||||||||
| 154 | } | ||||||||||||||||||||
| 155 | } | ||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | 4 | for my $plugin ($self->output_plugins) { | |||||||||||||||||||
| 158 | 4 | $plugin->finalize; | |||||||||||||||||||
| 159 | } | ||||||||||||||||||||
| 160 | } | ||||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | 5 | 1; | |||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | __END__ | ||||||||||||||||||||