[Jifty-commit] r4525 - in Net-Jifty: .

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Wed Nov 21 16:18:02 EST 2007


Author: sartak
Date: Wed Nov 21 16:18:02 2007
New Revision: 4525

Modified:
   Net-Jifty/   (props changed)
   Net-Jifty/Makefile.PL
   Net-Jifty/lib/Net/Jifty.pm

Log:
 r45449 at onn:  sartak | 2007-11-20 19:56:58 -0500
 Add some date and email-related methods


Modified: Net-Jifty/Makefile.PL
==============================================================================
--- Net-Jifty/Makefile.PL	(original)
+++ Net-Jifty/Makefile.PL	Wed Nov 21 16:18:02 2007
@@ -8,6 +8,8 @@
 requires        'YAML';
 requires        'URI';
 requires        'Encode';
+requires        'DateTime';
+requires        'Email::Address';
 
 build_requires  'Test::More';
 build_requires  'Test::MockObject';

Modified: Net-Jifty/lib/Net/Jifty.pm
==============================================================================
--- Net-Jifty/lib/Net/Jifty.pm	(original)
+++ Net-Jifty/lib/Net/Jifty.pm	Wed Nov 21 16:18:02 2007
@@ -5,6 +5,8 @@
 use Encode;
 use URI;
 use LWP::UserAgent;
+use DateTime;
+use Email::Address;
 
 =head1 NAME
 
@@ -410,6 +412,73 @@
            @_
 }
 
+=head2 load_date Date
+
+Loads a yyyy-mm-dd date into a L<DateTime> object.
+
+=cut
+
+sub load_date {
+    my $self = shift;
+    my $ymd  = shift;
+
+    # XXX: this is a temporary hack until Hiveminder is pulled live
+    $ymd =~ s/ 00:00:00$//;
+
+    my ($y, $m, $d) = $ymd =~ /^(\d\d\d\d)-(\d\d)-(\d\d)$/
+        or confess "Invalid date passed to load_date: $ymd. Expected yyyy-mm-dd.";
+
+    return DateTime->new(
+        time_zone => 'floating',
+        year      => $y,
+        month     => $m,
+        day       => $d,
+    );
+}
+
+=head2 email_eq Email, Email
+
+Compares two email address. Returns true if they're equal, false if they're not.
+
+=cut
+
+sub email_eq {
+    my $self = shift;
+    my $a    = shift;
+    my $b    = shift;
+
+    # if one's defined and the other isn't, return 0
+    return 0 unless (defined $a ? 1 : 0)
+                 == (defined $b ? 1 : 0);
+
+    return 1 if !defined($a) && !defined($b);
+
+    # so, both are defined
+
+    for ($a, $b) {
+        s/<nobody>/<nobody\@localhost>/;
+        my ($email) = Email::Address->parse($_);
+        $_ = lc($email->address);
+    }
+
+    return $a eq $b;
+}
+
+=head2 is_me Email
+
+Returns true if the given email looks like it is the current user's.
+
+=cut
+
+sub is_me {
+    my $self = shift;
+    my $email = shift;
+
+    return 0 if !defined($email);
+
+    return $self->email_eq($self->email, $email);
+}
+
 =head1 SEE ALSO
 
 L<Jifty>, L<Net::Hiveminder>


More information about the Jifty-commit mailing list