Re: [cgiapp] packages autouse?

2009-06-12 Thread Porta
I saw it, but unless I use the superloader, it still need to define the
names of the modules I want to use.And, regarding the superloader, I'm lazy
enough to want to use all the packages within a given folder, but not just
every possible module in the world...
Still, a good suggestion.

On Fri, Jun 12, 2009 at 1:38 AM, Cees Hek cees...@gmail.com wrote:

 Are you perhaps looking for Class::Autouse?  Not something I would use
 myself, but it may help you be more lazy in your programming...

 Cheers,

 Cees

 On Fri, Jun 12, 2009 at 2:11 AM, Porta julian.po...@gmail.com wrote:

  Hey, folks.
  Question:
  I was wondering if anyone else (than me) thinks is annoying to declare
 the
  use of all the required models (objects? packages?) you're using in
 your
  CA app?More, when working with CAD, on each controller you need to repeat
  use MyApp::Foo; use MyApp::Bar; etc.
 
  Assuming you're working with a persistent instance (means no need to do a
  cold start of your app on each request, so no problem to load all your
 app
  packages in memory) why not have *something* to manage the use of all
 the
  involved packages and reduce the repeated code on each package start.
 
  Thoughts?
 
  #  CGI::Application community mailing list  
  ####
  ##  To unsubscribe, or change your message delivery options,  ##
  ##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
  ####
  ##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
  ##  Wiki:  http://cgiapp.erlbaum.net/ ##
  ####
  
 
 

 #  CGI::Application community mailing list  
 ####
 ##  To unsubscribe, or change your message delivery options,  ##
 ##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
 ####
 ##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
 ##  Wiki:  http://cgiapp.erlbaum.net/ ##
 ####
 



#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] packages autouse?

2009-06-12 Thread Michael Peters

Porta wrote:

I saw it, but unless I use the superloader, it still need to define the
names of the modules I want to use.And, regarding the superloader, I'm lazy
enough to want to use all the packages within a given folder, but not just
every possible module in the world...
Still, a good suggestion.


I usually do something similar with some of my mod_perl programs to preload them 
into memory but you could probably do something similar. You could use it like:


use MyProject::AutoUse;

And it could look something like:

package MyProject::AutoUse;
use File::Find qw(find);

BEGIN {
find(
{
wanted = sub {
return unless m/\.pm$/;
return if /^\.?#/;# skip emacs droppings
my $module = $1;
$module =~ s/\//::/g;

my $pkg = MyProject::$module;
eval use $pkg;;
die Problem loading $pkg:\n\n$@ if $@;
},
no_chdir = 1
},
'/path/to/project/lib/MyProject'
);
}


caveat: not tested but should give you the general idea.

--
Michael Peters
Plus Three, LP


#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] packages autouse?

2009-06-12 Thread Porta
nicemuch closer, indeed.

On Fri, Jun 12, 2009 at 10:09 AM, Michael Peters mpet...@plusthree.comwrote:

 Porta wrote:

 I saw it, but unless I use the superloader, it still need to define the
 names of the modules I want to use.And, regarding the superloader, I'm
 lazy
 enough to want to use all the packages within a given folder, but not just
 every possible module in the world...
 Still, a good suggestion.


 I usually do something similar with some of my mod_perl programs to preload
 them into memory but you could probably do something similar. You could use
 it like:

 use MyProject::AutoUse;

 And it could look something like:

 package MyProject::AutoUse;
 use File::Find qw(find);

 BEGIN {
find(
{
wanted = sub {
return unless m/\.pm$/;
return if /^\.?#/;# skip emacs droppings
my $module = $1;
$module =~ s/\//::/g;

my $pkg = MyProject::$module;
eval use $pkg;;
die Problem loading $pkg:\n\n$@ if $@;
},
no_chdir = 1
},
'/path/to/project/lib/MyProject'
);
 }


 caveat: not tested but should give you the general idea.

 --
 Michael Peters
 Plus Three, LP



 #  CGI::Application community mailing list  
 ####
 ##  To unsubscribe, or change your message delivery options,  ##
 ##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
 ####
 ##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
 ##  Wiki:  http://cgiapp.erlbaum.net/ ##
 ####
 



#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] packages autouse?

2009-06-12 Thread Rhesa Rozendaal

Michael Peters wrote:

Porta wrote:

I saw it, but unless I use the superloader, it still need to define the
names of the modules I want to use.And, regarding the superloader, I'm lazy
enough to want to use all the packages within a given folder, but not just
every possible module in the world...
Still, a good suggestion.


I usually do something similar with some of my mod_perl programs to preload them 
into memory but you could probably do something similar. You could use it like:




Heh, I use Module::Pluggable for that in my startup.pl:

use Module::Pluggable require = 1, search_path = [qw(
  My
  Other::Stuff
)];
__PACKAGE__-plugins;

That would load everything under My::* and Other::Stuff::*.

(Module::Pluggable is in core)

rhesa

#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] packages autouse?

2009-06-12 Thread Richard Jones

Rhesa Rozendaal wrote:

Heh, I use Module::Pluggable for that in my startup.pl:

use Module::Pluggable require = 1, search_path = [qw(
  My
  Other::Stuff
)];
__PACKAGE__-plugins;

That would load everything under My::* and Other::Stuff::*.


Can Module::Pluggable be used as an alternative to Module::Find? I load 
all my Model::DB classes up front in a BEGIN block in MyApp::Base, like 
this:


BEGIN {
  use Module::Find;

  Module::Find::setmoduledirs('path/to/lib');
  Module::Find::useall MyApp::DB;
}

use Module::Pluggable
  require = 1,
  search_dirs = [ 'path/to/lib/MyApp/DB' ]

For this to work I need the Module::Pluggable equivalent of useall().
--
Richard Jones

#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] packages autouse?

2009-06-12 Thread Jaldhar H. Vyas

On Fri, 12 Jun 2009, Richard Jones wrote:

Can Module::Pluggable be used as an alternative to Module::Find? I load all 
my Model::DB classes up front in a BEGIN block in MyApp::Base, like this:


BEGIN {
 use Module::Find;

 Module::Find::setmoduledirs('path/to/lib');
 Module::Find::useall MyApp::DB;
}

use Module::Pluggable
 require = 1,
 search_dirs = [ 'path/to/lib/MyApp/DB' ]

For this to work I need the Module::Pluggable equivalent of useall().


Does this (from the docs) do the trick?

quote
Or if you want to instantiate each plugin rather than just return the
   name

   package MyClass;
   use Module::Pluggable instantiate = 'new';

   and then

   # whatever is passed to 'plugins' will be passed
   # to 'new' for each plugin
   my @plugins = $mc-plugins(@options);
/quote

For non object-oriented modules you could combine require and instantiate 
= import for an equivalent to use.


--
Jaldhar H. Vyas jald...@braincells.com

#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




[cgiapp] packages autouse?

2009-06-11 Thread Porta
Hey, folks.
Question:
I was wondering if anyone else (than me) thinks is annoying to declare the
use of all the required models (objects? packages?) you're using in your
CA app?More, when working with CAD, on each controller you need to repeat
use MyApp::Foo; use MyApp::Bar; etc.

Assuming you're working with a persistent instance (means no need to do a
cold start of your app on each request, so no problem to load all your app
packages in memory) why not have *something* to manage the use of all the
involved packages and reduce the repeated code on each package start.

Thoughts?

#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] packages autouse?

2009-06-11 Thread P Kishor
On Thu, Jun 11, 2009 at 11:11 AM, Portajulian.po...@gmail.com wrote:
 Hey, folks.
 Question:
 I was wondering if anyone else (than me) thinks is annoying to declare the
 use of all the required models (objects? packages?) you're using in your
 CA app?More, when working with CAD, on each controller you need to repeat
 use MyApp::Foo; use MyApp::Bar; etc.

 Assuming you're working with a persistent instance (means no need to do a
 cold start of your app on each request, so no problem to load all your app
 packages in memory) why not have *something* to manage the use of all the
 involved packages and reduce the repeated code on each package start.

 Thoughts?

Mark Stosberg's Titanium tries to get around that very problem by
doing all the use-ing for you. So, you just have to 'use Titanium'. On
the other hand, if you sub-class CGI::App, and then sub-class your
sub-class, you can do all the use-ing just once.

CGI::App -- SuperSubClass with tons of use -- Sub classes.

What I do find annoying is the number steps involved in adding a new
run mode, esp. when using CAD.

First, add the new run mode to the dispatch table.

Second, add the run mode to the setup in the module (assuming one is
not using AutoRunmode... some problems have been alluded to using
AutoRunmode, esp. in mod_perl environments.

Third, create the darn run mode.

Fourth, create the template for the run mode.

Dunno if there is a quicker way.





-- 
Puneet Kishor

#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] packages autouse?

2009-06-11 Thread Rhesa Rozendaal

P Kishor wrote:

What I do find annoying is the number steps involved in adding a new
run mode, esp. when using CAD.

First, add the new run mode to the dispatch table.

Second, add the run mode to the setup in the module (assuming one is
not using AutoRunmode... some problems have been alluded to using
AutoRunmode, esp. in mod_perl environments.

Third, create the darn run mode.

Fourth, create the template for the run mode.

Dunno if there is a quicker way.


There are two that I know of: CAP::AutoRunmode and CAP::RunmodeDeclare. The 
latter is mine, but the former works great too.


I don't think you should count creating a template. After all,

runmode hello { return Hello world! }

is perfectly valid.

rhesa

#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] packages autouse?

2009-06-11 Thread Rhesa Rozendaal

Porta wrote:

Hey, folks.
Question:
I was wondering if anyone else (than me) thinks is annoying to declare the
use of all the required models (objects? packages?) you're using in your
CA app?More, when working with CAD, on each controller you need to repeat
use MyApp::Foo; use MyApp::Bar; etc.


I think that's a feature, not a bug. It depends on the size of your code base, 
but I generally like to see what a class imports or inherits, so I don't have 
to chase up the inheritance hierarchy to find out what's defined where.


See also Ovid's posts on this topic, e.g.
* http://use.perl.org/~Ovid/journal/39039
* http://use.perl.org/~Ovid/journal/38862

rhesa


#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] packages autouse?

2009-06-11 Thread Rhesa Rozendaal

Porta wrote:

Hey, folks.
Question:
I was wondering if anyone else (than me) thinks is annoying to declare the
use of all the required models (objects? packages?) you're using in your
CA app?More, when working with CAD, on each controller you need to repeat
use MyApp::Foo; use MyApp::Bar; etc.


If you must, see Modern::Perl for inspiration.

rhesa

#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] packages autouse?

2009-06-11 Thread P Kishor
On Thu, Jun 11, 2009 at 12:26 PM, Rhesa Rozendaalp...@rhesa.com wrote:
 P Kishor wrote:

 What I do find annoying is the number steps involved in adding a new
 run mode, esp. when using CAD.

 First, add the new run mode to the dispatch table.

 Second, add the run mode to the setup in the module (assuming one is
 not using AutoRunmode... some problems have been alluded to using
 AutoRunmode, esp. in mod_perl environments.

 Third, create the darn run mode.

 Fourth, create the template for the run mode.

 Dunno if there is a quicker way.

 There are two that I know of: CAP::AutoRunmode and CAP::RunmodeDeclare. The
 latter is mine, but the former works great too.

Hi Rhesa, CAP::RunmodeDeclare looks very interesting. I actually used
CAP::AutoRunmode successfully, but I remember seeing a thread on this
mailing list itself about CAP::AutoRunmode causing problems under
certain circumstances, particularly under mod_perl.


 I don't think you should count creating a template. After all,

    runmode hello { return Hello world! }

 is perfectly valid.

You are correct. Counting making a template as a step in the process
is a bit unfair, however, my point was not to criticize the tools
negatively. My point is -- this is something that could be made
easier.

There has been some discussion on the Mac side of things (I am a Mac
user) about what is termed as the untitled document syndrome. Some
programs force you to first save a document somewhere before they let
you type in it. This causes a problem, it gives rise to impedance. The
user now has to think of where to save the document, what to call it
(ever noticed the slew of untitled.txt and untitled1.txt and so on
in a user's hard disk? There are several other programs that you can
just launch and start typing, without having to think about where you
are saving the document and what you are going to call it. Some even
save automatically, every few seconds. This lowers the impedance,
makes things easier.

That is the ideal that I am trying to push for. Right now, the way
things are, we have way too many steps. Sure, one would want to have a
template separate from the program as that is good practice. But,
could the other steps be minimized?

I am not familiar with Ruby on Rails, but I have heard that this ease
is what made RoR so popular.

Most web applications need certain basic scaffolding... logging in and
user authentication is one of them, and sadly, a pretty complicated
scaffolding -- allow creation, editing and deletion of users,
retrieval and resetting of passwords, allow logging in and logging
out, store the session information, and so on. The Titanium project
seems like a great start in this direction, but I am sure a lot of
work is required beyond just packaging a bunch of modules together.

This list has programmers and developers way more experienced and
accomplished than I am or will ever be. Hopefully, we will be able to
develop cgiapp into a tool that can make it easy for folks like me to
develop easy, secure, fast and attractive web applications easily.



 rhesa




-- 
Puneet Kishor http://www.punkish.org/
Carbon Model http://carbonmodel.org/
Charter Member, Open Source Geospatial Foundation http://www.osgeo.org/
Science Commons Fellow, Geospatial Data http://sciencecommons.org
Nelson Institute, UW-Madison http://www.nelson.wisc.edu/
---
collaborate, communicate, compete
===
Sent from Madison, WI, United States

#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] packages autouse?

2009-06-11 Thread Richard Jones

P Kishor wrote:
[..]


Hi Rhesa, CAP::RunmodeDeclare looks very interesting. I actually used
CAP::AutoRunmode successfully, but I remember seeing a thread on this
mailing list itself about CAP::AutoRunmode causing problems under
certain circumstances, particularly under mod_perl.


Perhaps you were referring to this one:
http://www.mail-archive.com/cgiapp@lists.erlbaum.net/msg07094.html

If so, it turned out to be a combination of some of the older C::A 
plugin versions and some self-inflicted errors in my code which made it 
appear that AutoRunmode was not working in a persistent environment. See 
here for more details:

http://www.mail-archive.com/cgiapp@lists.erlbaum.net/msg07144.html
http://www.mail-archive.com/cgiapp@lists.erlbaum.net/msg07180.html

AutoRunmode works fine under mod_perl - at least it does for me.
--
Richard Jones

#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] packages autouse?

2009-06-11 Thread Cees Hek
Are you perhaps looking for Class::Autouse?  Not something I would use
myself, but it may help you be more lazy in your programming...

Cheers,

Cees

On Fri, Jun 12, 2009 at 2:11 AM, Porta julian.po...@gmail.com wrote:

 Hey, folks.
 Question:
 I was wondering if anyone else (than me) thinks is annoying to declare the
 use of all the required models (objects? packages?) you're using in your
 CA app?More, when working with CAD, on each controller you need to repeat
 use MyApp::Foo; use MyApp::Bar; etc.

 Assuming you're working with a persistent instance (means no need to do a
 cold start of your app on each request, so no problem to load all your app
 packages in memory) why not have *something* to manage the use of all the
 involved packages and reduce the repeated code on each package start.

 Thoughts?

 #  CGI::Application community mailing list  
 ####
 ##  To unsubscribe, or change your message delivery options,  ##
 ##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
 ####
 ##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
 ##  Wiki:  http://cgiapp.erlbaum.net/ ##
 ####
 



#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####