Added a number of new tests and example XML files for them.
[email-reminder.git] / EmailReminder / BirthdayEvent.pm
blob5e0b476012b33c6def9ea8d4c1878287902c5179
1 # This file is part of Email-Reminder.
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.
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.
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.
18 package EmailReminder::BirthdayEvent;
20 use strict;
21 use warnings;
22 use overload '""' => \&str;
23 use EmailReminder::Utils;
24 use EmailReminder::YearlyEvent;
26 require Exporter;
27 our @ISA = ("EmailReminder::YearlyEvent", "Exporter");
28 our @EXPORT = qw(get_th get_email);
30 # XML tags, attributes and values
31 my $EMAIL_TAG = 'email';
33 sub str {
34 my ($this) = @_;
35 return $this->get_type . ':' . $this->get_id . ') ' . $this->get_name . ' - ' . $this->get_date;
38 # Hard-coded value for this event's type (class method)
39 sub get_type
41 return 'birthday';
44 # Number of fields this event adds to its parent (class method)
45 sub get_nb_fields
47 return EmailReminder::YearlyEvent->get_nb_fields() + 1;
50 sub get_email
52 my ($this) = @_;
53 return EmailReminder::Utils::get_node_value($this->{XML_NODE}, $EMAIL_TAG);
56 sub set_email
58 my ($this, $new_value) = @_;
59 return EmailReminder::Utils::set_node_value($this->{XML_NODE}, $EMAIL_TAG, $new_value);
62 # Returns the age of the person (starts at 0 years old)
63 sub get_occurence
65 my $this = shift;
67 my $age = $this->EmailReminder::YearlyEvent::get_occurence();
69 return defined($age) ? ($age - 1) : undef;
72 sub get_subject
74 my $this = shift;
76 my $name = $this->get_name();
77 my $age = $this->get_occurence();
78 my $when = $this->{"WHEN"};
80 if ($age and $when eq "today") {
81 return "$name is now $age";
83 else {
84 return "${name}'s birthday";
88 sub get_message_body
90 my $this = shift;
92 # destination user
93 my $first_name = shift;
95 # birthday person
96 my $name = $this->get_name();
97 my $email = $this->get_email();
98 my $age = $this->get_occurence();
99 my $when = $this->{"WHEN"};
101 my $age_string = $age ? "turning $age" : "getting one year older";
102 my $email_message = $email ? "\n\nYou can reach $name at $email." : "";
104 my $message = <<MESSAGEEND;
105 Hi $first_name,
107 I just want to remind you that $name is $age_string $when.$email_message
108 MESSAGEEND
110 return $message;