[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cgiapp] Re: ANNOUNCE: CGI::Application::Plugin::LogDispatch


On Tue, 14 Dec 2004 11:52:36 +1300, Dan Horne <suppressed> wrote:
> Thanks to all who responded - cleared things up a bit.
> 
> Quoting Michael Peters <suppressed>:
> 
> > If you are interested, I've been meaning to make a CAP::Log4perl plugin
> > but haven't had the time just yet. I will in a few days though. If you
> > wanted to you could take a shot at it yourself. Else, I will hopefully
> > have one by the end of the week.
> 
> I've often felt I should contribute something to this project ... I always use
> everyone else's plugins. Not sure that I know how to write one myself. I didn't

Well, everyone that asks and answers questions on this mailing list is
contributing in a very important way.  By answering a question, you
are helping a user with a problem.  But more importantly, by asking a
question, you stimulate discussion and in turn help a lot more people.
 The search engines are full of info from the mailing list and that
raises the chances of new users finding us much more than anything
else.

> see anything in the Wiki about how to write a plugin. Does anyone have any doco?

Of course adding to the code base is always a welcome addition :)

I don't think there is a guide to writing plugins, but your best bet
is just looking at the code.  Find a plugin that works in a way you
like, and make a copy of the code and work from there by stripping
things out and adding things in (remember to check the license so you
know what responsibilities you will have if you want to release your
module).

Another way to start writing plugins is to add the functionality you
want to your own application Base class and develop it and use it
until you are happy.  Then try and abstract the configuration and
access to a plugin module.

Generally, the plugins I have written are very simple and really just
give your apps the ability to configure and retrieve and object.  For
example, this LogDispatch plugin only really provides 2 functions, one
to configure the Log::Dispatch object (log_config), and one to
retrieve it on demand (log).   After you strip away all the comments,
and checks, you are left with something like this

sub log_config {
  my $self = shift;
  # stuff the configuration away somewhere
}

sub log {
  my $self = shift;
  if (We don't already have a Log::Dispatch object) {
    # create a new Log::Dispatch object using the configuration
    # parameters passed to log_config, or use some simple
    # defaults
    $self->{__LOG_OBJECT} = new Log::Dispatch(...);
  }
  return $self->{__LOG_OBJECT};
}

So there really isn't all that much to it...  You still have to do a
little work to setup the Exporter stuff, but you can copy that from
one of the other existing plugins.

If you do plan to build a Log::Log4perl plugin, remember that it
automatically creates a singleton object, so it will probably work a
little bit differently than the Log::Dispatch plugin.

Hope that helps a little bit...

-- 
Cees Hek

---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/suppressed/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.