[Catalyst] Date::Calc and Date::Calendar with Catalyst?

Jonathan Rockway jon at jrock.us
Fri Feb 23 17:16:53 GMT 2007


Dave Morriss wrote:
> Question 1: Will I need to build my own plugin to achieve what I want,
> or is there another way?

It's unlikely that you'll want to use a plugin.  Plugins should be
reserved for things that modify Catalyst's usual request cycle.
Pagecache, Static::Simple, and ConfigLoader are good examples of
plugins; Prototype is a bad example.

I'm not exactly sure what you're trying to do, but it sounds like you
want a regular Perl module:

  package MyOrg::Calendar;
  use base 'Exporter';
  my @EXPORT = qw(workdays_between_dates);

  sub workdays_between_dates {
     my ($from, $to) = @_;
     return 42; # modify to taste
  }

  ...

Then in Catalyst, you'd do something like:

  package MyOrg::Vacations::Controller::GiveMeADayOff;
  use base 'Catalyst::Controller';
  use MyOrg::Calendar;

  sub get_a_day_off : Path {
      my ($self, $c, $date) = @_;

      $c->stash(template => 'day_off.tt');

      my $last_day_off =
       $c->model('Vacataions')->get_last_vacation_day_for($c->user);

      if(workdays_between_dates($last_day_off, $date) > 5){
         $c->stash(error =>
                   "Only one vacation day per week is allowed,
                    slacker!");
      }
      else {
         $c->model('Vacations')->add_vacation($date, $c->user);
      }

      ... # you get the idea
  }

Hope this helps a bit.  Basically you should read up on writing Perl
modules; I think that's what you really want here.  man perlmod should help.

> Question 2: Is there a plugin writer's HOWTO?

There is; at:

http://search.cpan.org/~jrockway/Catalyst-Manual-5.700501/lib/Catalyst/Manual/WritingPlugins.pod

But I don't think you need a plugin.

> Thanks

Regards,
Jonathan Rockway

-- 
package JAPH;use Catalyst qw/-Debug/;($;=JAPH)->config(name => do {
$,.=reverse qw[Jonathan tsu rehton lre rekca Rockway][$_].[split //,
";$;"]->[$_].q; ;for 1..4;$,=~s;^.;;;$,});$;->setup;



More information about the Catalyst mailing list