Re: [Catalyst] Catalyst Unicode woes ...

2007-08-09 Thread Jonathan T. Rockway
On Thu, Aug 09, 2007 at 10:27:27AM +0200, Tobias Kremer wrote:
 I have the problem that up until now everything worked absolutely fine without
 C::P::Unicode, Template::Stash::ForceUTF8, Template::Provider::Encoding or any

ForceUTF8 is a hack hack hack.  If your program doesn't work without it,
it's completely broken.

C::P::Unicode is necessary though.  If you don't know why, read the
source and the various perl unicode manpages.  There's a lot to
understand, and I've explained it too many times to care anymore.
Google it.

The gist of it is this:

outside octets - Encode::decode(...) - manipulate it
 - Encode::encode(...) - the user

If you do manipulation before you decode, your app will break.  If you
do manipulation after you encode, your app will break.

Anyway, a whole article about unicode and Catalyst is here:

http://www.catalystframework.org/calendar/2006/21

Learn and enjoy.

Regards,
Jonathan Rockway

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] How to execute controller at startup

2007-08-07 Thread Jonathan T. Rockway
 On Mon, Aug 06, 2007 at 11:33:04PM -0700, Aditya Verma wrote:
  Hi All,
  
  Thank you very much for all your valuable comments at appreciate your quick
  response.
  
  I have one more query.
  I have implemented a Plugin. How can I call a plugin method from controller
  outside of the controller methods.
 You shouldn't.
 
 If you need to do that, the method shouldn't be in a plugin.
 
 Don't hack up your Catalyst app, fix your design :)

Expanding on what mst said, keep in mind that plugins are reserved for
things that need to affect the request cycle.  If you just need some
functionality, write a regular module.  If it needs $c, pass in $c.
Component base classes are also possible, and are a better approach
than plugins.  (See C::Plugin::FormBuilder
vs. C::Controller::FormBuilder.  Both are on CPAN so you can compare
the approaches.)

Finally, phaylon's Extending Catalyst guide:

http://search.cpan.org/~jrockway/Catalyst-Manual-5.700701/lib/Catalyst/Manual/ExtendingCatalyst.pod

  suppose i have a Plugin named Catalyst::Plugin::MyPlugin contains a method
  called sub myFunc {}
 
 That should be my_func, not myFunc. This is perl, not java. Please stick to
 the correct naming conventions for things.

TMTOWTDI, but your way is rather unconventional.  Identifiers should
be lowercase (%karma_for), constants should be uppercase
($SECRET_OF_THE_UNIVERSE), and modules should be CamelCase
(MyApp::SomeThing).  Anything else will make people like mst mad
because it's really really ugly.

Hope this helps.

Regards,
Jonathan Rockway

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] mod_proxy and https

2007-08-06 Thread Jonathan T. Rockway
On Mon, Aug 06, 2007 at 12:23:43PM -0500, Dave Rolsky wrote:
 On Mon, 6 Aug 2007, Duncan Ferguson wrote:
 For SSL you'd send X-Forwarded-Is-SSL with some true value.

 Hopefully this will be merged into the Catalyst trunk sometime soonish.

I think we intend to get this into the next maint release (5.7009).
We just need to write some tests to make sure the new Engine stuff
works correctly, then we'll release.

Regards,
Jonathan Rockway

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Ajax

2007-08-05 Thread Jonathan T. Rockway
On Sun, Aug 05, 2007 at 11:26:10AM +0100, Matt S Trout wrote:
 Always, -always- use View::JSON rather than doing the serialisation direct.

I tend to use Catalyst::Controller::REST and let it handle
serialization / deserialization for me.  Technically not MVC, but
since it's not code I have to look at, I don't care.  It's a bit
smarter than View::JSON in that it will return XML (etc.)
automagically if the client requests it.  Convenient.

It also provides un-Viewing (deserialization of the request body),
which doesn't fit nicely into the MVC pattern.  At least not in a way
I can see in my current caffeine-deprived state.

YMMV.

Regards,
Jonathan Rockway

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] do I need to load Apache::DBI?

2007-07-30 Thread Jonathan T. Rockway
On Mon, Jul 30, 2007 at 06:19:09PM -0400, Perrin Harkins wrote:
 On 7/30/07, Matt S Trout [EMAIL PROTECTED] wrote:
  I used to consider it a neat hack. After some time with the internals,
  some fun explicitly disabling it within DBIC since it sometimes broke
  our reconnect code, and even then discovering I could often solve
  client mod_perl problems by removing the line that loaded it from
  httpd.conf, I reclassified it was 'awful'.

 Your implication is that Apache::DBI doesn't work, as opposed to
 simply clashing with some of the DBIC code that tries to manage the
 same connections.  It works just fine.  It's widely-used and does what
 it was intended to without known bugs.

I think mst's point was if you don't know why to use Apache::DBI,
don't use it.  Generally good advice.

Regards,
Jonathan Rockway

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [BULK] - Re: [Catalyst] flash with DBIC session storage

2007-07-28 Thread Jonathan T. Rockway
On Sat, Jul 28, 2007 at 09:15:36AM +0200, Tobias Kremer wrote:
 I think you're right: The error is due to my poor-man's approach of 
 load-testing.

BTW, how are you invoking ab?  I think each request should get its own
cookie, which means the same id shouldn't be being inserted more than
once.

Finally, you might want to try siege instead of ab.

Regards,
Jonathan Rockway

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [BULK] - Re: [Catalyst] flash with DBIC session storage

2007-07-27 Thread Jonathan T. Rockway
On Fri, Jul 27, 2007 at 11:57:01AM -0700, Mesdaq, Ali wrote:
 Are you sure that InnoDB would solve this issue? Even if just a row was
 locked and you have 2 inserts at the exact same time how would that
 resolve the issue?

One transaction would succeed and the other would fail.  If you want
different behavior, you'll have to change the isolation level (or
actualy, in this case, rethink your app).

It's more of an issue of this:

User visits page A.
User visits page B in another tab.
User submits form A.
User submits form B.
A updates the flash.
B updates the flash.
Page A2 loads with whatever flash won.
Page B2 loads with whatever flash won.

The point is that both transaction A and transaction B can't go
through.  Web apps aren't designed to be hit concurrently by the same
user; it just doesn't make sense (or work) when you're keeping state.
One state has to win; this is what the DB error is telling you.

You could setup locks over [submit, update flash, display flash]:

User submits form A.
Form A gets the lock.
User submits form B.
B submission blocks waiting for the lock.
A updates the flash.
Page A2 loads.
A unlocks.
B gets the lock.
B updates the flash.
...

This adds a lot of complexity, though.  Is this really a problem that
your users experience, or is it an artifact of poor load testing
practices?

Regards,
Jonathan Rockway

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] flash with DBIC session storage

2007-07-27 Thread Jonathan T. Rockway
On Fri, Jul 27, 2007 at 06:11:03PM -0700, Mesdaq, Ali wrote:
 I think in the case of the person who initially emailed the group the
 problem is poor load testing. But it does bring up the point of better
 handling of exception statements by DBIx. 

DBIx:: is a generic namespace for DBI extensions.  DBIx::Class is
abbreviated as DBIC.  (This comes up a lot, I should add it to a FAQ
or something.)

 The DBIx::Class::ResultSet::find_or_create(): call should handle
 this exception better because it can happen in tons of different
 places and its not always an application or benchmarking issue.

What do you think it should do?  create failed.  Only your app knows
what to do in that situation.

Maybe you are suggesting that errors be hidden so your app silently
loses data?  I am not in favor of that.

 In high load situations you WILL see this happen.

I have a feeling that your app is broken then.  I often do dumbass
load testing on my apps and don't have any problems with transactions
failing unchecked.

I really think you should read about transactional isolation and how
deadlocks/conflicts are handled by your RDBMS.

The Berkeley DB has really good documentation on both of these things,
describing both theory and how to avoid common problems with the
library itself.  SQLite's docs are also good.


 To illustrate here is an example: Your DB has a first_name table to
 store user first names You get a flood of new people registering and
 you normalize their first names to get id's 2 Users have the first
 name of Tom which does not exist yet You call
 DBIx::Class::ResultSet::find_or_create(): Both calls detect the name
 does not exist Both calls insert with one getting this error
 
 Now there is no real way to handle this in your app unless you do a lot
 of concurrency checking or queuing of inserts. 

Rollback and try again.  Your DBMS' docs will tell you about the best
strategy for dealing with this case.  I'm sure there's a good-enough
generic solution... if someone knows it, I would like to hear.

Anyway, you should probably continue this thread on the DBIC mailing
list instead.  DBIC has *nothing* to do with Catalyst.

Regards,
Jonathan Rockway

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] setup_home() bug

2007-07-20 Thread Jonathan T. Rockway
On Mon, Jul 09, 2007 at 04:53:18PM -0400, Adam Herzog wrote:
  Okay. I added Catalyst::Utils::env_value(), and updated Catalyst.pm 
  Index: t/unit_utils_env_value.t
  Index: lib/Catalyst.pm
  Index: lib/Catalyst/Utils.pm

Thanks for the patch, it looks great.  The only problem is that your
mail client seems to have wrapped some long lines, and even when I
manually fix it Cpatch is unable to apply the patch.

If you could regenerate and send it unmunged, then I'll get this
applied ASAP.

Regards,
Jonathan Rockway

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Angerwhale + CPAN

2007-07-19 Thread Jonathan T. Rockway
On Thu, Jul 19, 2007 at 02:31:10AM +, Yousef AlHashemi wrote:
  Hello,
 
   This may be a little bit off-topic as it's more about CPAN than
  Catalyst, but I've almost always had trouble installing modules that have
  lots of dependencies with cpan. All I do is simply invoke the cpan shell
  (with the `cpan` command), and type install Angerwhale. After installing
  lots of packages, cpan dies (and hangs without returning to the prompt). The
  last 55 lines of the cpan output (up to the point where it hangs) are posted
  here: http://pastebin.com/m69751dc0 . Your help is greatly appreciated it.

It looks like Crypt::RSA failed which caused Crypt::OpenPGP to fail.

Also, why is the output messed up, i.e.:

 *** ExtUtilq::AutoIlstall ilstallation diniqhed.

That should say *** ExtUtils::AutoInstall installation finished.
Also, it looks like some output of various make test runs are
interleaved with each other, leading me to believe that your CPAN.pm is
seriously fucked.  Maybe upgrade to a new version or try CPANPLUS?

Once your CPAN starts working again, manually install Crypt::OpenPGP
and let me know how that goes.  That's the hardest dep to get going,
mostly because the various Crypt:: authors seem to enjoy writing tests
that take 15 minutes to run.

Regards,
Jonathan Rockway

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Proper way to perform cleanups on server shutdown?

2007-07-11 Thread Jonathan T. Rockway
On Wed, Jul 11, 2007 at 09:03:29AM -0700, John Napiorkowski wrote:
 I can demonstrate this by placing an END block in my
 root modules (the MyApp.pm module)
 
 END {
   print got END BLOCK!\n;
 }
 
 This will never run under the conditions I have
 described.
 
 HOWEVER, if I set SIG handlers manually like so:
 
 $SIG{INT} = sub { print got INT!\n };
 $SIG{TERM} = sub { print got TERM!\n };
 
 END {
   print got END BLOCK!\n;
 }
 
 Then the END block does run.

Is this different from what you would expect?

try:

  $ perl -e 'END { print going away\n }; sleep 1 while(1);' 
  ^C
  $ _

compared to:

  $ perl -e 'END { print going away\n }'
  going away
  $ _ 

From what I've observed, a signal won't trigger END blocks even
outside of Catalyst.

Regards,
Jonathan Rockway

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Re: Announcing the first Catalyst SwagReward!

2007-05-21 Thread Jonathan T. Rockway
On Sun, May 20, 2007 at 06:14:35PM +0200, A. Pagaltzis wrote:
 * Mike Whitaker [EMAIL PROTECTED] [2007-05-20 16:50]:
  If all goes well it will probably be fully programmatic but will
  almost certainly involve Python.
  
  Ooo. Dunno about that. :)
  
  Can't help feeling that it's not really within the spirit of a
  Catalyst-related prize to use Python - after all, the obvious
  home for such a script in the end is in the MojoMojo source
  tree, surely.
 

BTW, I'm working on this.

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] OT: security through obscurity (was: Encrypt/Decrypt URI)

2007-05-18 Thread Jonathan T. Rockway
On Fri, May 18, 2007 at 03:37:27PM +0200, A. Pagaltzis wrote:
 Just because this is a pet peeve of mine:
 
 Yes it is.

Obscurity is a constant factor.  As soon as one person figures out
your obfuscation, it's useless.  When someone figures our your real
security, it does them no good at all.  Since there are 6_000_000_000
people in the world, it's likely that someone has already figured our
your obscurity, so only real security matters.

It's like saying O(2) instead of O(1).  Sure, ``O(2)'' is twice as
slow as O(1), but that's irrelevant and you sound stupid when you make
a distinction.

Finally, the hmac+md5 urls sounds sound from a security standpoint,
but it's a really dumb way to write a web app.

Regards,
Jonathan Rockway

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] After the RoR vs. PHP Mac/PC ad skits on reddit ...

2007-05-18 Thread Jonathan T. Rockway
On Fri, May 18, 2007 at 04:10:13PM +0100, Matt S Trout wrote:
 http://markkeating.me.uk/catror/

Nice.  Upvote @ reddit:

http://programming.reddit.com/info/1rqhe/comments

Regards,
Jonathan Rockway

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Too greedy name-based Virtual Host

2007-05-16 Thread Jonathan T. Rockway
On Wed, May 16, 2007 at 11:54:34AM +0200, Xavier Robin wrote:

  Here comes the Virtual Host :
 
  VirtualHost site2.domain.tld:80
   ServerNamesite2.domain.tld:80
   DocumentRoot  /home/xrobin/MIAPE/root
   LogLevel  debug
   ErrorLog  /home/xrobin/catalyst_error_log
   Location /
   SetHandler   modperl
   PerlResponseHandler  MIAPE
   /Location
  /VirtualHost

Where's the rest of the config.  Standing alone, that's probably fine.
But who knows what else you have in your httpd.conf :)

Also, I think the VirtualHost directive is supposed to be an IP (or
*):

  NameVirtualHost *:80
  VirtualHost *:80ServerName site1/VirtualHost
  VirtualHost *:80ServerName site2/VirtualHost

I have a feeling that your config looks like:

  NameVirtualHost site1
  VirtualHost site1ServerName site1/VirtualHost
  VirtualHost site2ServerName site2/VirtualHost

I think that even though site1 and site2 resolve to the same IP,
Apache doesn't realize that site2 is supposed to do vhosting.  But I
don't really know how Apache handles corner cases... try the obvious
suggestions above and if it still doesn't work, please paste your
whole config.

Regards,
Jonathan Rockway

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


[Catalyst] attn MicroMason View users

2007-05-15 Thread Jonathan T. Rockway
Hi all,

A few months ago (err... 7), I pushed Catalyst::View::MicroMason
0.04_01 to the CPAN (with some fixes people wanted).  I never got any
feedback on this version, so I haven't made it stable yet.  If
you're a MicroMason user, please try it and tell me what problems you
encounter.  If it's perfect and makes sunshine rain down upon us all,
please also report that ;)

When it's looking good, I'll make it stable so that you all can easily
benefit from the changes.

Regards,
Jonathan Rockway

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


[Catalyst] Template::Declare view available

2007-05-15 Thread Jonathan T. Rockway
Hi all,

I have more than just MicroMason views :)  While I was at the YAPC::Asia
hackathon last month, I was around a bunch of Jifty people and decided
to write Catalyst::View::Template::Declare.  If you're not familiar with
TD, it's a module for writing HTML templates in Perl:

template foo = sub {
  html {
head { title { Hello, world.  } };
body {
  p { This is a paragraph. }
}
  }
};

Catalyst::View::Template::Declare integrates TD with Catalyst, so if
you're interested in TD, you might want to give it a try.  The module
is in my CPAN directory, and it's available via git:

   $ git clone git://git.jrock.us/Catalyst-View-Template-Declare

The web interface is at:

   http://git.jrock.us/?p=Catalyst-View-Template-Declare.git;a=summary

Please let me know how it works for you.  IMHO, it's a bit nicer than
the Jifty version since you can have your template definitions in
multiple modules (under your View's namespace), and everything is
compiled when you start your app (so that template syntax errors
prevent your app from starting).  There's also some extra syntactic
sugar floating around (::Tags gets auto-imported, for example).

Regards,
Jonathan Rockway

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] getting $c in model unit test

2007-05-15 Thread Jonathan T. Rockway
On Tue, May 15, 2007 at 09:48:05AM -0400, Nathan Gray wrote:
 Does anyone have an example unit test that has access to $c?

As others have mentioned, this is probably a sign of a poorly designed
API.  If you decide to continue further, you'll probably want to use
Test::MockObject to setup a fake Catalyst app/context.  I have a class
called Angerwhale::Test::Application (code is on CPAN) that will setup a fake
Angerwhale context:

   sub context {
   my $args = shift;
   my $config = $args-{config};
   
   my $c = Test::MockObject-new;
   $c-set_always( 'stash', {} );
   
   $config = { %{$config||{}},
   %{LoadFile('root/resources.yml')||{}}
 };
   
   $c-set_always( 'config', $config );
   
   # fake logging (doesn't do anything)
   my $log = Test::MockObject-new;
   $log-set_always( 'debug', undef );
   $c-set_always( 'log', $log);
   
   # fake cache (always generates a cache miss)
   my $cache = Test::MockObject-new;
   $cache-set_always( 'get', undef );
   $cache-set_always( 'set', undef );
   $c-set_always( 'cache', $cache );
   
   # TODO: model / etc.

   return $c;
   }

As you can see, I only set up the stuff I use; in this case the stash,
a log, and $c-cache.  If I use something else, the test will die and I
can investigate why.

I also have a model function that returns an instance
of a model (and could be generalized to return any Component):

   sub model {
   my $name = shift;
   croak need name unless $name;
   my $args = shift;
   my $context = $args-{context} || context();
   
   $name =~ s/\W//g;
   $name = Angerwhale::Model::$name;
   
   eval require $name;
   croak error loading $name: $@ if $@;
   
   my $model;
   eval {
   $model = $name-COMPONENT($context, $args-{args});
   };
   croak didn't get a model: $@ if $@ || !$model;
   
   return $model;
   }

There's more than one way to do this, but it works for me.

Regards,
Jonathan Rockway

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/