[Catalyst] Re: Defining ARRAY in Config::General config
"Pavel A. Karoukin" writes: > On Tue, Sep 21, 2010 at 8:06 AM, Emanuele Zeppieri wrote: > >> To obtain single value arrays with the syntax in question, the above >> line should be: >> >> my $conf = Config::General->new( -ConfigFile => 'config.conf', >> -ForceArray => 1 ); >> >> > How I can pass this -ForceArray to Config::General in my catalyst app? Upgrade Config::Any to version 0.20, which passes it by default. If you don't want to specify a direct versioned requirement for an indirect dependency in your Makefile.PL, you can require Catalyst::Plugin::ConfigLoader version 0.29, which depends on Config::Any version 0.20. -- ilmari "A disappointingly low fraction of the human race is, at any given time, on fire." - Stig Sandbeck Mathisen ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] FastCGI startup strangeness
"Daniel J. Luke" writes: > I noticed today that an app I'm working on will start fine only if the > user who is running the app can read the current directory (ie, if I'm > starting it as a user dedicated to running the app, that user must > have read permission on CWD). > > Couldn't load class (MYAPP::Script::FastCGI) because: Can't locate > MYAPP/Script/FastCGI.pm: Permission denied at > /path/to/perl-5.20.0/lib/site_perl/5.20.0/Catalyst/ScriptRunner.pm line 13. > Catalyst::ScriptRunner::find_script_class("Catalyst::ScriptRunner", > "MYAPP", "FastCGI") called at > /path/to/perl/perl-5.20.0/lib/site_perl/5.20.0/Catalyst/ScriptRunner.pm line > 42 > Catalyst::ScriptRunner::run("Catalyst::ScriptRunner", "MYAPP", > "FastCGI") called at /path/to/MYAPP/script/MYAPP_fastcgi.pl line 4 > > strace shows the difference between a successful launch and a failed > one is whether we get EACCESS or ENOENT when looking for > ./MYAPP/Script/FastCGI.pm This is due to require as of 5.18 no longer silently ignoring errors when trying to load a module: require dies for unreadable files When require encounters an unreadable file, it now dies. It used to ignore the file and continue searching the directories in @INC [perl #113422]. https://metacpan.org/pod/perl5180delta#require-dies-for-unreadable-files Combined with the fact that Catalyst::ScriptRunner tries to load the optional (but in your case non-existent) MYAPP::Script::FastCGI, and that '.' is in @INC by the default, it gives this (somewhat annoying) behaviour. For daemons it is generally a good idea to cd to / or some application-specific directory before starting up, to avoid e.g. it accidentally hanging onto a mount point. > failure: > stat("./MYAPP/Script/FastCGI.pmc", 0x7fffa8eba720) = -1 EACCES (Permission > denied) > stat("./MYAPP/Script/FastCGI.pm", 0x7fffa8eba660) = -1 EACCES (Permission > denied) > > success: > stat("./MYAPP/Script/FastCGI.pmc", 0x7fff80e76db0) = -1 ENOENT (No such file > or directory) > stat("./MYAPP/Script/FastCGI.pm", 0x7fff80e76cf0) = -1 ENOENT (No such file > or directory) > > I didn't see this documented anywhere - am I missing some obvious reason why > this behavior is desired? -- "I use RMS as a guide in the same way that a boat captain would use a lighthouse. It's good to know where it is, but you generally don't want to find yourself in the same spot." - Tollef Fog Heen ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
[Catalyst] Config-only components
Hi all, Castaway mentioned the idea of having components defined entirely by config entries, without the need for any actual class files on disk, and I was bored, so I went ahead and implemented it. For each config key matching ^([MVC]|Model|View|Controller):: it checks if the corresponding component already exists, and if it doesn't it creates it on the fly. The base class is set to ->config->{$component}->{base_class} if it exists, Catalyst::$component (with [MVC] expanded to the full component type) otherwise. Here's the patch against 5.70/trunk, feedback welcome. lib/Catalyst.pm | 51 ++ lib/Catalyst/Utils.pm | 23 +++ t/lib/Catalyst/Component/Implicit.pm | 16 ++ t/lib/Catalyst/Controller/Implicit.pm |4 ++ t/lib/Catalyst/Model/Implicit.pm |4 ++ t/lib/Catalyst/View/Implicit.pm |4 ++ t/unit_core_component_dynamic.t | 31 7 files changed, 121 insertions(+), 12 deletions(-) === lib/Catalyst/Utils.pm == --- lib/Catalyst/Utils.pm (revision 36505) +++ lib/Catalyst/Utils.pm (local) @@ -79,6 +79,29 @@ return $class; } +=head2 expand_component_type( $class ); + +Replaces M, V and C components of the class name with Model, View and +Controller, respectively. + + MyApp::C::Foo becomes MyApp::Controller::Foo + My::App::C::Foo becomes Mapp::Controller::Foo + +=cut + +sub expand_component_type { +my ($class) = @_; + +my %expand = qw/ M Model + V View + C Controller + /; + +$class =~ s/(?<=::)([MVC])(?=::)/$expand{$1}/; + +return $class; +} + =head2 class2env($class); Returns the environment name for class. === lib/Catalyst.pm == --- lib/Catalyst.pm (revision 36505) +++ lib/Catalyst.pm (local) @@ -1878,19 +1878,46 @@ Catalyst::Utils::ensure_class_loaded( $component, { ignore_loaded => 1 } ); -my $module = $class->setup_component( $component ); -my %modules = ( -$component => $module, -map { -$_ => $class->setup_component( $_ ) -} grep { - not exists $comps{$_} -} Devel::InnerPackage::list_packages( $component ) -); +$class->_load_component_and_children( $component, \%comps ); +} + +# For component-esque config keys with no corresponding module yet +# loaded, try to create it on the fly. + +my $prefix = join '|', map { m/::(.*)/ } @paths; +my @config_comps = grep /^(?:$prefix)::/, keys %{ $class->config }; +$comps{"$class\::$_"} = 1 for @config_comps; + +for my $suffix ( @config_comps ) { +my $component = "$class\::$suffix"; + +next if $class->components->{ $component }; + +my $base = delete $class->config->{ $suffix }->{ base_class } +|| Catalyst::Utils::expand_component_type("Catalyst::$suffix"); + +Catalyst::Utils::ensure_class_loaded( $base ); +{ no strict 'refs'; unshift @{"$component\::ISA"}, $base } + +$class->_load_component_and_children( $component, \%comps ); +} +} + +sub _load_component_and_children { +my ($class, $component, $comps) = @_; + +my $module = $class->setup_component( $component ); +my %modules = ( +$component => $module, +map { +$_ => $class->setup_component( $_ ) +} grep { +not exists $comps->{$_} +} Devel::InnerPackage::list_packages( $component ) +); -for my $key ( keys %modules ) { -$class->components->{ $key } = $modules{ $key }; -} +for my $key ( keys %modules ) { +$class->components->{ $key } = $modules{ $key }; } } === t/lib/Catalyst/Component(new directory) == === t/lib/Catalyst/Component/Implicit.pm == --- t/lib/Catalyst/Component/Implicit.pm(revision 36505) +++ t/lib/Catalyst/Component/Implicit.pm(local) @@ -0,0 +1,16 @@ +package Catalyst::Component::Implicit; +use base qw/Catalyst::Component/; + +use Catalyst::Utils; + +sub COMPONENT { +my ($self, $c, $arguments) = @_; +my $class = ref $self || $self; + +# Inject an inner package intoto the subclass +{ no strict 'refs'; @{"$class\::Sub::ISA"} = @{"$class\::ISA"} } + +return $self->NEXT::COMPONENT( $c, $arguments ); +} + +1; === t/lib/Catalyst/Controller (new directory) == === t/lib/Catalyst/Controller/Implicit.pm == --- t/lib/Catalyst/Controller/Implicit.pm (revision 36505) +++ t/lib/Catalyst/Contr
[Catalyst] Re: More Catalyst slides
Jonathan Rockway <[EMAIL PROTECTED]> writes: > Hello, Hi Jon, > I gave a Catalyst talk at Frozen Perl last weekend. The slides are > here: > > http://www.jrock.us/fp2008/catalyst/start.html […] > The code is also available; it's linked to from the slides. I just went through the slides and code after nuking my entire set of non-deb-packaged modules (I wanted to play around with CPANPLUS::Dist::deb :) and noticed a few missing things in the dependencies and MANIFEST, here's a quick patch: [EMAIL PROTECTED]:~/src$ diff -ur KitiWiki-0.01{.orig,}/Makefile.PL --- KitiWiki-0.01.orig/Makefile.PL 2008-02-16 17:20:55.0 + +++ KitiWiki-0.01/Makefile.PL 2008-02-22 03:23:10.0 + @@ -9,11 +9,13 @@ requires 'Catalyst::Plugin::ConfigLoader'; requires 'Catalyst::Plugin::Static::Simple'; requires 'Catalyst::Runtime' => '5.7012'; +requires 'Catalyst::Model::Adaptor'; requires 'Catalyst::Devel'; # for the talk requires 'Encode'; requires 'File::Slurp'; requires 'Moose'; requires 'MooseX::Types::Path::Class'; +requires 'MosseX::AttributeHelpers;' requires 'Time::HiRes'; requires 'YAML'; build_requires 'Directory::Scratch'; [EMAIL PROTECTED]:~/src$ diff -ur KitiWiki-0.01{.orig,}/MANIFEST --- KitiWiki-0.01.orig/MANIFEST 2008-02-16 17:22:13.0 + +++ KitiWiki-0.01/MANIFEST 2008-02-22 03:24:26.0 + @@ -56,3 +56,4 @@ t/wiki-backend.t t/wiki-revision-sort.t t/wiki-validation.t +wiki_pages -- ilmari "A disappointingly low fraction of the human race is, at any given time, on fire." - Stig Sandbeck Mathisen ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
[Catalyst] Re: X-Forwarded-For
Bill Moseley <[EMAIL PROTECTED]> writes: > On Tue, Apr 01, 2008 at 11:38:15PM -0400, Andy Grundman wrote: >> >> When using X-Forwarded-For you cannot trust any value that is not >> added by your own upstream proxy, so we only want to use the last >> value in the list. > > Ah, right. In this case I've got more than one proxy which > that code doesn't expect. I can find a work-around. How about patching C::Engine::Apache to take a list of proxy IPs in its config and use the last IP in the header that is not among these? -- ilmari "A disappointingly low fraction of the human race is, at any given time, on fire." - Stig Sandbeck Mathisen ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
[Catalyst] ConfigLoader patch: pretty syntax for plugins
Hi all, I noticed that ConfigLoader's pretty syntax¹ (particluarly with Config::General) for model, view and controller config didn't extend to plugin config. [1]: Like this: bar baz instead of bar baz Here's a patch that extends the feature to cover plugins: === Changes == --- Changes (revision 55488) +++ Changes (local) @@ -5,6 +5,7 @@ Config::General format - fix up pod to explain in more detail how to pass options to each driver class (Sergio Salvi) +- add nice syntax for plugins as well as models/views/controllers 0.20 Fri May 02 2008 - sort configs by filename for loading (RT #31498) === lib/Catalyst/Plugin/ConfigLoader.pm == --- lib/Catalyst/Plugin/ConfigLoader.pm (revision 55488) +++ lib/Catalyst/Plugin/ConfigLoader.pm (local) @@ -227,7 +227,7 @@ values => delete $config->{ lc $_ } || delete $config->{ $_ } }, grep { ref $config->{ lc $_ } || ref $config->{ $_ } } -qw( Component Model M View V Controller C ) +qw( Component Model M View V Controller C Plugin ) ); foreach my $comp ( @components ) { === t/20-mock_load.t == --- t/20-mock_load.t(revision 55488) +++ t/20-mock_load.t(local) @@ -1,6 +1,6 @@ package MockApp; -use Test::More tests => 9; +use Test::More tests => 10; use Cwd; $ENV{ CATALYST_HOME } = cwd . '/t/mockapp'; @@ -21,3 +21,4 @@ is( __PACKAGE__->config->{ 'view' }, 'View::TT::New' ); is( __PACKAGE__->config->{ 'foo_sub' }, 'x-y' ); is( __PACKAGE__->config->{ 'literal_macro' },'__DATA__' ); +is( __PACKAGE__->config->{ 'Plugin::Zot' }->{ zoot },'zooot'); === t/mockapp/mockapp.pl == --- t/mockapp/mockapp.pl(revision 55488) +++ t/mockapp/mockapp.pl(local) @@ -4,4 +4,5 @@ 'Model::Baz' => { qux => 'xyzzy' }, foo_sub => '__foo(x,y)__', literal_macro => '__literal(__DATA__)__', +Plugin=> { Zot => { zoot => 'zooot' } }, } -- ilmari "A disappointingly low fraction of the human race is, at any given time, on fire." - Stig Sandbeck Mathisen ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
[Catalyst] Re: How to send raw HTTP response
Tomas Doran <[EMAIL PROTECTED]> writes: > On 27 Sep 2008, at 19:48, Matt S Trout wrote: >> Just call $c->write($chunk) with each chunk of data as you get it. >> >> Catalyst will automatically send headers before the first chunk for >> you. >> >> Do -not- rely on STDOUT being an appropriate filehandle to print to, >> that's >> an accident of the engine design and could easily go away. > > Unfortunately, if you're using Archive::Zip, you don't get an option to > get chunks you can call $c->write with, you _need_ to write to a file > handle.. (And this isn't the only module on CPAN that'd behave like > this). (…) > Thoughts / pointing out the module I missed on CPAN? Catalyst::Response in 5.80 trunk implements ->print, just for this puropse (I needed it for Text::CSV_XS' ->print($fh, $fields) method). -- ilmari "A disappointingly low fraction of the human race is, at any given time, on fire." - Stig Sandbeck Mathisen ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/