App-Birthday

 view release on metacpan or  search on metacpan

bin/birthday  view on Meta::CPAN

    <$conf_fh>;
};

my $json     = JSON::PP->new->allow_nonref;
my $input_hr = $json->decode( $input );
my $conf_hr  = $json->decode( $conf );

for (keys %$input_hr) {
    if ($$input_hr{$_}{date} eq $today or $opt{x}) {
        if ($opt{y}){
            verify_mails( $_, $input_hr, $conf_hr, $opt{i} );
        } else {
            send_mails( $_, $input_hr, $conf_hr, $opt{i} );
        }
    }
}

1;
__END__

=head1 NAME

bin/birthday  view on Meta::CPAN

=head1 SYNOPSIS

B<birthday> <option>

=head1 OPTION

   -h : help
   -i <file> : user defined input file, default "birthday.json"
   -c <file> : user defined configuration file, default "config.json"
   -x        : send to all users in "config.file", no date verification
   -y        : verify configuration and input - no mail will be sent

=head1 DESCRIPTION

It sends birthday e-mails to your friends, on their anniversary date.

I have a bad habit that I almost always forget the birthdays of my
friends and colleagues. To solve this, I try to 'cheat' and write this
script and add it to my I<crontab>.

It sends an e-mail at his/hers anniversary date to a friend and a

bin/birthday  view on Meta::CPAN


The list of birthday children are saved in a JSON file, default is
F<birthday.json>, in the same directory as script. Any other file can be
selected using option I<-i>. See below for file format.

Additionally you need a configuration file for your e-mail system. This
file is also in JSON format and default is F<configuration.json>, in the
same directory as script. The file format is described below. Any other
file can be selected using option I<-c>.

To verify the configuration and input file use I<-y>. Here it prints all
mails and configuration to STDOUT instead of sending them per mail. It
is useful for testing and validation.

=head2 Input Format

The format of input file can be best described by an example. Imagin Bob
has 3 friends: Carol, Ted, Alice. The following JSON structure can be
saved, e.g. in F<birthday.json>.

    {

lib/App/Birthday.pm  view on Meta::CPAN

package App::Birthday;
our @EXPORT = qw/usage version send_mails verify_mails/;# Symbols to autoexport (:DEFAULT tag)
use base qw/Exporter/;
use Mail::Sender;

our $VERSION = '0.4';

sub send_mails {
    my ($name, $in_hr, $cfg_hr, $in_file) = @_;
    my @to      = ();
    my $me      = $$cfg_hr{maintainer};
    my $subject = $in_file.' config file. You sent a birtday mail for: '; # subject only for maintainer

lib/App/Birthday.pm  view on Meta::CPAN

        });

    # secret E-Mail only to me, as a reminder
    $sender->MailMsg({
        to      => $me,
        subject => $subject.$$in_hr{$name}{email},
        msg     => $$in_hr{$name}{text}
        });
}

sub verify_mails {
    my ($name, $in_hr, $cfg_hr, $in_file) = @_;
    my @to      = ();
    my $me      = $$cfg_hr{maintainer};
    my $subject = $in_file.' config file. You sent a birtday mail for: '; # subject only for maintainer
    # send E-Mail to all friends of birthday child
    if (${$$in_hr{$name}{friends}{names}}[0] == "others"){
        push @to, $$in_hr{$_}{email}.',' for (grep { $_ ne $name } keys %$in_hr); # all - name
    } else {
        push @to, $$in_hr{$_}{email}.',' for (@{$in_hr{$$in_hr{$name}{friends}{names}}});
    }

lib/App/Birthday.pm  view on Meta::CPAN


=head1 SUBROUTINES/METHODS

=head2 send_mails

Main function, send mail due to a F<birthday.json> file and a given
configuration file

=cut

=head2 verify_mails

It verifies configuration and input entries. It sends no mail but prints
all output to STDOUT.

=cut

=head2 usage

description and examples of usage



( run in 0.954 second using v1.01-cache-2.11-cpan-73692580452 )