"Fossies" - the Fresh Open Source Software Archive

Member "email-reminder-0.8.1/EmailReminder/BirthdayEvent.pm" (14 Mar 2015, 2530 Bytes) of package /linux/privat/email-reminder-0.8.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "BirthdayEvent.pm" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 0.7.7_vs_0.7.8.

    1 # This file is part of Email-Reminder.
    2 #
    3 # Email-Reminder is free software; you can redistribute it and/or
    4 # modify it under the terms of the GNU General Public License as
    5 # published by the Free Software Foundation; either version 3 of the
    6 # License, or (at your option) any later version.
    7 #
    8 # Email-Reminder is distributed in the hope that it will be useful,
    9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
   10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   11 # General Public License for more details.
   12 #
   13 # You should have received a copy of the GNU General Public License
   14 # along with Email-Reminder; if not, write to the Free Software
   15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
   16 # 02110-1301, USA.
   17 
   18 package EmailReminder::BirthdayEvent;
   19 
   20 use strict;
   21 use warnings;
   22 use overload '""' => \&str;
   23 use EmailReminder::Utils;
   24 use EmailReminder::YearlyEvent;
   25 
   26 use base qw(EmailReminder::YearlyEvent);
   27 
   28 # XML tags
   29 __PACKAGE__->mk_accessors(qw(email));
   30 
   31 sub str {
   32     my ($self) = @_;
   33     return $self->get_type . ':' . $self->get_id . ') ' . $self->get_name . ' - ' . $self->get_date;
   34 }
   35 
   36 # Hard-coded value for this event's type (class method)
   37 sub get_type
   38 {
   39     return 'birthday';
   40 }
   41 
   42 # Number of fields this event adds to its parent (class method)
   43 sub get_nb_fields
   44 {
   45     my ($self) = @_;
   46     return $self->SUPER::get_nb_fields() + 1;
   47 }
   48 
   49 sub valid_email
   50 {
   51     my ($class, $new_value) = @_;
   52     # ToDo: do checking on the email address
   53     return $new_value;
   54 }
   55 
   56 # Returns the age of the person (starts at 0 years old)
   57 sub get_occurence
   58 {
   59     my $self = shift;
   60 
   61     my $age = $self->EmailReminder::YearlyEvent::get_occurence();
   62 
   63     return defined($age) ? ($age - 1) : undef;
   64 }
   65 
   66 sub get_subject
   67 {
   68     my $self = shift;
   69 
   70     my $name = $self->get_name();
   71     my $age  = $self->get_occurence();
   72     my $when = $self->{"WHEN"} || '';
   73 
   74     if ($age and $when eq "today") {
   75         return "$name is now $age";
   76     }
   77     else {
   78         return "${name}'s birthday";
   79     }
   80 }
   81 
   82 sub get_message_body
   83 {
   84     my $self = shift;
   85 
   86     # birthday person
   87     my $name  = $self->get_name();
   88     my $email = $self->get_email();
   89     my $age   = $self->get_occurence();
   90     my $when  = $self->{"WHEN"} || '';
   91     
   92     my $age_string = $age ? "turning $age" : "getting one year older";
   93     my $email_message = $email ? "\n\nYou can reach $name at $email." : "";
   94 
   95     my $message = <<"MESSAGEEND";
   96 I just want to remind you that $name is $age_string $when.$email_message
   97 MESSAGEEND
   98 
   99     return $message;
  100 }
  101 
  102 1;