[erlang-questions] defining default functions for a module

Jayson Vantuyl kagato@REDACTED
Wed Nov 11 01:57:04 CET 2009


Basically, the router is a gen_event, the modules are gen_event  
handlers plugged into the router.

Each handler implements the functions as something like:

> handle_event({i_actually_handle_this,Params}) ->
>   do_something(Params);
> handle_event(_) ->
>   unhandled.

If the goal is route some message, that works pretty well.  If you  
need the return value, it's not quite so easy, but it's an option that  
is "handled" for most cases.

Just a thought.

On Nov 10, 2009, at 4:48 PM, Pablo Platt wrote:

> My callbacks are not dynamic so I won't be leaking atoms.
> I can have a dummy function but it makes dev longer and modules less  
> readable.
> I'm trying to do something similar to objects and classes in OO.
>
> How gen_event is related?
>
> From: Jayson Vantuyl <kagato@REDACTED>
> To: Pablo Platt <pablo.platt@REDACTED>
> Cc: erlang-questions <erlang-questions@REDACTED>
> Sent: Wed, November 11, 2009 2:32:04 AM
> Subject: Re: [erlang-questions] defining default functions for a  
> module
>
> Maybe require a callback module to have a dummy function, or is the  
> function name really dynamic?  If it is dynamic (and your program is  
> network accessible), are you sure you won't be leaking atoms (i.e.  
> exposing an exciting DOS)?
>
> Also, have you considered gen_event?  They're quite lovely, I assure  
> you.
>
> On Nov 10, 2009, at 3:25 PM, Pablo Platt wrote:
>
> > Hi,
> >
> > I have a module that acts as a router.
> > It gets requests and pass them to callback modules.
> > Callback modules should have a function for each case unless they  
> need to do something specific.
> >
> > Is it ok to use erlang:function_exported/3 to check if the  
> callback module defined the needed function
> > and if not to execute the default defined in the router?
> > Will it cost me in performance or is it against the way I should  
> do things in erlang?
> >
> > I thought a behavior will solve my need but it only recommend a  
> module structure for the compiler.
> >
> > Thanks
> >
> >
> >
>
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
>
>



More information about the erlang-questions mailing list