[Catalyst-commits] r14247 - in trunk/examples/CatalystAdvent: . lib/CatalystAdvent/Controller root

caelum at dev.catalyst.perl.org caelum at dev.catalyst.perl.org
Sat Jan 21 16:30:33 GMT 2012


Author: caelum
Date: 2012-01-21 16:30:33 +0000 (Sat, 21 Jan 2012)
New Revision: 14247

Modified:
   trunk/examples/CatalystAdvent/catalystadvent.conf
   trunk/examples/CatalystAdvent/lib/CatalystAdvent/Controller/Calendar.pm
   trunk/examples/CatalystAdvent/root/wrapper.tt
Log:
clean up some of the calendar code

Modified: trunk/examples/CatalystAdvent/catalystadvent.conf
===================================================================
--- trunk/examples/CatalystAdvent/catalystadvent.conf	2012-01-14 19:08:42 UTC (rev 14246)
+++ trunk/examples/CatalystAdvent/catalystadvent.conf	2012-01-21 16:30:33 UTC (rev 14247)
@@ -1,3 +1,3 @@
 <Controller::Calendar>
-#    retired "The calendar has been retired, stay tuned for the Catalyst monthly blog!"
+    retired 1
 </Controller::Calendar>

Modified: trunk/examples/CatalystAdvent/lib/CatalystAdvent/Controller/Calendar.pm
===================================================================
--- trunk/examples/CatalystAdvent/lib/CatalystAdvent/Controller/Calendar.pm	2012-01-14 19:08:42 UTC (rev 14246)
+++ trunk/examples/CatalystAdvent/lib/CatalystAdvent/Controller/Calendar.pm	2012-01-21 16:30:33 UTC (rev 14247)
@@ -43,20 +43,20 @@
 sub base : Chained('/base') PathPart('') CaptureArgs(0) {}
 
 sub index : Chained('base') PathPart('') Args(0) {
-    my ( $self, $c ) = @_;
+    my ($self, $c) = @_;
 
-    my $now = $c->stash->{now};
-    my $start_date = $now->clone->set(month => 12, day => 1);
+    my @years = $self->_years($c);
 
-    opendir DIR, $c->path_to('root') or die "Error opening root: $!";
-    my @years = sort grep { /\d{4}/ } readdir DIR;
-    closedir DIR;
+    if (not $self->retired) {
+        my $now = $c->stash->{now};
 
-    my $days_until = $start_date->delta_days($now)->delta_days;
+        if (not ($now->month == 12 || ($now->month == 1 || $now->month == 2))) {
+            my $start_date = $now->clone->set(month => 12, day => 1);
 
-    if (not $self->retired) {
-        if (not ($now->month == 12 || ($now->month == 1 || $now->month == 2))) {
+            my $days_until = $start_date->delta_days($now)->delta_days;
+
             $c->stash(days_until => $days_until);
+
             pop @years if @years && $years[-1] == $now->year;
         }
     }
@@ -67,10 +67,14 @@
     $c->stash(previous_years => \@years) if @years;
 
     $c->go($self->action_for('year'), [$years[-1]], []) if @years;
+}
 
-#    $c->stash->{year}     = $year;
-#    $c->stash->{calendar} = calendar( 12, $year );
-#    $c->stash->{template} = 'year.tt';
+sub _years {
+    my ($self, $c) = @_;
+
+    opendir my $dir, $c->path_to('root') or die "Error opening root: $!";
+
+    return sort { $a <=> $b } grep { /^\d{4}\z/ } readdir $dir;
 }
 
 =head2 get_year

Modified: trunk/examples/CatalystAdvent/root/wrapper.tt
===================================================================
--- trunk/examples/CatalystAdvent/root/wrapper.tt	2012-01-14 19:08:42 UTC (rev 14246)
+++ trunk/examples/CatalystAdvent/root/wrapper.tt	2012-01-21 16:30:33 UTC (rev 14247)
@@ -24,9 +24,9 @@
 <p class="center">In the mean time, you might want to check our archives.</p>
         [%- END %]
     [%- ELSE %]
-<h2>[% retired %]</h2>
+        [%- PROCESS retired.tt -%]
         [%- IF previous_years %]
-<p class="center">Please check out the archive of awesome articles from previous
+<p class="center">Please check out the archive of articles from previous
 years.</p>
         [%- END %]
     [%- END %]




More information about the Catalyst-commits mailing list