[erlang-questions] defining default functions for a module

Pablo Platt pablo.platt@REDACTED
Wed Nov 11 02:06:00 CET 2009


I'm not sure but I don't think it's useful in my case.

I'm trying to implement a CRUD - crate read update delete router for resources with callback functions.
In the default case the router can do any one of the actions but callback functions can override this behavior.
For example a callback function can check for permissions and won't let unauthorized user to delete a resource.




________________________________
From: Jayson Vantuyl <kagato@REDACTED>
To: Pablo Platt <pablo.platt@REDACTED>
Cc: erlang-questions <erlang-questions@REDACTED>
Sent: Wed, November 11, 2009 2:57:04 AM
Subject: Re: [erlang-questions] defining default functions for a module

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