[Catalyst] Plugin::Session lazy start

2012-05-23 Thread Dag-Erling Smørgrav
I have an application that uses sessions with a FastMmap store.  This
application also includes a custom script (using Catalyst::ScriptRole)
used to perform certain administrative tasks from the command line.

The problem is that Catalyst tries to unlink and recreate the session
cache every time it starts (somewhere in the bowels of MyApp-setup(), I
imagine).  This is obviously a bad idea if the application is running,
but it is a problem even if the application isn't running if the session
cache is owned by a different user (e.g. www) than the one that runs the
script (e.g. des).

Is there a way to have C::Plugin::Session (or C::P::S::Store::FastMmap)
initialize the cache on first use instead of at startup?

As an alternate solution, is there a way to have it use a different file
name every time it starts?

DES
-- 
Dag-Erling Smørgrav - d...@des.no

___
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] Module::Install::Catalyst and Test::Prereqs conflict?

2012-05-23 Thread Robert Rothenberg
I think that there is a problem using the Makefile.PL with Test::Prereqs and
similar modules.

When I run prereqs_ok(), I get the following error:

_get_prereqs: Error loading Makefile.PL: Can't call method
load_all_extensions on an undefined value at
/usr/local/share/perl/5.10.1/Module/Install.pm line 206, DATA line 4267.
BEGIN failed--compilation aborted at ./Makefile.PL line 4, DATA line 4267.

not ok 1 -  Makefile.PL did not return a true value.
#

#   Failed test '   Makefile.PL did not return a true value.
# '
#   at /usr/local/share/perl/5.10.1/Test/Prereq.pm line 220.
#
# Looks like you failed 1 test of 1.
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/1 subtests




___
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] Plugin::Session lazy start

2012-05-23 Thread Dag-Erling Smørgrav
Will Crawford billcrawford1...@gmail.com writes:
 Dag-Erling Smørgrav d...@des.no writes:
  Is there a way to have C::Plugin::Session (or C::P::S::Store::FastMmap)
  initialize the cache on first use instead of at startup?
 { ..., unlink_on_exit = 0 } in your config.

delete the cache when you're done is very different from don't create
the cache until you actually need it.

  As an alternate solution, is there a way to have it use a different file
  name every time it starts?
 Personally I go with having a relative path in the myapp_local.conf
 that puts them all in a tmp/ subdirectory of where I'm running the
 server, then an absolute path in myapp.conf for the real thing.

The script runs with the exact same configuration as the application,
including myapp_local.conf.  That's the whole point of using a Catalyst
script instead of a standalone program.

DES
-- 
Dag-Erling Smørgrav - d...@des.no

___
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] sort %hash in TT with Catalyst

2012-05-23 Thread Tomasz Gromowski

Hello,
how can I sort hash reference by values, I found some solution:
http://mail.template-toolkit.org/pipermail/templates/2005-June/007501.html
But I  don't know where can I add virtual method.

3) Similar to 2. Add a virtual method to your hashes. Just add this above your 
process call. (Note: You might need to add: 'use Template::Stash;') :
$Template::Stash::HASH_OPS-{ sort_keys_by } = sub {
  my ($hash, $sort_field) = @_;
return sort {
   $hash-{$a}-{$sort_field}=  $hash-{$b}-{$sort_field}
} keys %$hash
};

then you can do:
[% FOREACH r = ref.sort_keys_by('number') %]
a href=/program?id=[% r %][% ref.$r.title _   _ ref.$r.number %]/a
[% END %]


I try to add virtual method to  View  but i get error:

|Couldn't render template stats.tt: undef error - Can't use string (1) as a HASH ref 
while strict refs in use at View/HTML.pm line 15.|




___
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] Plugin::Session lazy start

2012-05-23 Thread Ashley Pond V
On Wed, May 23, 2012 at 1:58 AM, Dag-Erling Smørgrav d...@des.no wrote:
 As an alternate solution, is there a way to have it use a different file
 name every time it starts?

Here's a snippet to do that:

conf.yml
--
Plugin::Session:
  storage: /tmp/some-prefix-__UID__.session

MyApp.pm
--
 Plugin::ConfigLoader = {
 substitutions = {
 UID = sub { $ },
 },
 },

https://metacpan.org/module/Catalyst::Plugin::ConfigLoader

___
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] Plugin::Session lazy start

2012-05-23 Thread Alexander Hartmaier
Because I've just read perlvar: $REAL_USER_ID or $UID instead of $.

- Alex


Am 2012-05-23 15:54, schrieb Ashley Pond V:
 On Wed, May 23, 2012 at 1:58 AM, Dag-Erling Smørgrav d...@des.no wrote:
 As an alternate solution, is there a way to have it use a different file
 name every time it starts?
 Here's a snippet to do that:

 conf.yml
 --
 Plugin::Session:
   storage: /tmp/some-prefix-__UID__.session

 MyApp.pm
 --
  Plugin::ConfigLoader = {
  substitutions = {
  UID = sub { $ },
  },
  },

 https://metacpan.org/module/Catalyst::Plugin::ConfigLoader

 ___
 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/


***
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
***
Notice: This e-mail contains information that is confidential and may be 
privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
***

___
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] Plugin::Session lazy start

2012-05-23 Thread Dag-Erling Smørgrav
Dag-Erling Smørgrav d...@des.no writes:
 Thanks, that's a neat workaround (combined with unlink_on_exit).

I was wrong about that last bit - unlink_on_exit automatically defaults
to a sane value (unlink the file if you created it, leave it alone if it
already existed).  If anything, you'd want to set it to 0 so sessions
are persistent across server restarts.

BTW, this is not a perfect solution, since all processes owned by the
same user will now share a session cache.  However, this should rarely
(if ever) be a problem.

DES
-- 
Dag-Erling Smørgrav - d...@des.no

___
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] Plugin::Session lazy start

2012-05-23 Thread Dag-Erling Smørgrav
Alexander Hartmaier alexander.hartma...@t-systems.at writes:
 Because I've just read perlvar: $REAL_USER_ID or $UID instead of $.

assuming use English

DES
-- 
Dag-Erling Smørgrav - d...@des.no

___
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] Plugin::Session lazy start

2012-05-23 Thread Ashley Pond V
On Wed, May 23, 2012 at 7:42 AM, Alexander Hartmaier
alexander.hartma...@t-systems.at wrote:
 Because I've just read perlvar: $REAL_USER_ID or $UID instead of $.

I think this is generally excellent advice but I want to argue against
it in this case.

UID = sub { $ } is sufficiently semantic *and* edifying. E.g., Oh!
That's the special var for UID. It finally makes sense.

use English;
UID = sub { $UID } is redundant to point of being annoying and even
distracting (to me).

___
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] Role problems, Still

2012-05-23 Thread Kenneth S Mclane
I am having difficulty in getting my user to authenticate against the 
second realm. After successfully authenticating against the ldap server, I 
want to authenticate against the dbic realm as well as that is where the 
roles are stored. It seems to ignore a second call to $c-.authenticate.

I tried removing the default_realm = 'ldap' entry but it complained 
with an error of not find the user in the realm default. 

I looked at the Progressive module, but it seems to me that it stops as 
soon as the user authenticates.

I also have had no luck doing a find_or_create. Do I need to consolidate 
the roles into the users table? 

I even tried just creating a user in the user table figuring I could do a 
second step of updateing the users_to_roles table after that. I keep 
getting me.user is not valid in the context it is being used

Once again I can find no help in the docs. They simply do not address this 
situation. I have found that other people have solved this, but they don't 
seem to post the code that solved it, just something along the lines of I 
fixed it. That isn't of much help to us new folks.


Any help is appreciated.___
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] Role problems, Still

2012-05-23 Thread Tomas Doran

On 23 May 2012, at 16:37, Kenneth S Mclane wrote:

 I am having difficulty in getting my user to authenticate against the second 
 realm. After successfully authenticating against the ldap server, I want to 
 authenticate against the dbic realm as well as that is where the roles are 
 stored. It seems to ignore a second call to $c-.authenticate. 

In this case, I would be using the DBIC authentication store module (not the 
LDAP one), with the self_check Credential option + the auto_create_user option, 
and writing a check_password method (yourself) which looked up the user in LDAP 
and did the auth there…

If you want roles and other foreign keys etc - then you want the user row from 
DBIC to be master, and authentication to just be delegated down to that row 
instance..

Cheers
t0m


___
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] Module::Install::Catalyst and Test::Prereqs conflict?

2012-05-23 Thread Tomas Doran

On 23 May 2012, at 11:26, Robert Rothenberg wrote:

 I think that there is a problem using the Makefile.PL with Test::Prereqs and
 similar modules.
 
 When I run prereqs_ok(), I get the following error:
 
 _get_prereqs: Error loading Makefile.PL: Can't call method
 load_all_extensions on an undefined value at
 /usr/local/share/perl/5.10.1/Module/Install.pm line 206, DATA line 4267.
 BEGIN failed--compilation aborted at ./Makefile.PL line 4, DATA line 4267.

What leads you to suspect that this is anything to do with 
Module::Install::Catalyst?

I'd have guessed at a bug between Test::Prereqs and Module::Install itself, 
rather than the Catalyst specific extension..

Cheers
t0m


___
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] Module::Install::Catalyst and Test::Prereqs conflict?

2012-05-23 Thread Robert Rothenberg
On 23/05/12 17:06 Tomas Doran wrote:
 
 On 23 May 2012, at 11:26, Robert Rothenberg wrote:
 
 I think that there is a problem using the Makefile.PL with Test::Prereqs and
 similar modules.

 When I run prereqs_ok(), I get the following error:

 _get_prereqs: Error loading Makefile.PL: Can't call method
 load_all_extensions on an undefined value at
 /usr/local/share/perl/5.10.1/Module/Install.pm line 206, DATA line 4267.
 BEGIN failed--compilation aborted at ./Makefile.PL line 4, DATA line 4267.
 
 What leads you to suspect that this is anything to do with 
 Module::Install::Catalyst?
 
 I'd have guessed at a bug between Test::Prereqs and Module::Install itself, 
 rather than the Catalyst specific extension..

It occurs in some of the other modules that do the same thing, such as
Module::CPANTS::Kwalalitee::Prereq.


___
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] Module::Install::Catalyst and Test::Prereqs conflict?

2012-05-23 Thread Tomas Doran

On 23 May 2012, at 17:15, Robert Rothenberg wrote:

 On 23/05/12 17:06 Tomas Doran wrote:
 
 On 23 May 2012, at 11:26, Robert Rothenberg wrote:
 
 I think that there is a problem using the Makefile.PL with Test::Prereqs and
 similar modules.
 
 When I run prereqs_ok(), I get the following error:
 
 _get_prereqs: Error loading Makefile.PL: Can't call method
 load_all_extensions on an undefined value at
 /usr/local/share/perl/5.10.1/Module/Install.pm line 206, DATA line 4267.
 BEGIN failed--compilation aborted at ./Makefile.PL line 4, DATA line 4267.
 
 What leads you to suspect that this is anything to do with 
 Module::Install::Catalyst?
 
 I'd have guessed at a bug between Test::Prereqs and Module::Install itself, 
 rather than the Catalyst specific extension..
 
 It occurs in some of the other modules that do the same thing, such as
 Module::CPANTS::Kwalalitee::Prereq.
 

So nothing?

Cheers
t0m


___
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] Module::Install::Catalyst and Test::Prereqs conflict?

2012-05-23 Thread Robert Rothenberg
On 23/05/12 18:42 Tomas Doran wrote:
 
 On 23 May 2012, at 17:15, Robert Rothenberg wrote:
 
 On 23/05/12 17:06 Tomas Doran wrote:

 On 23 May 2012, at 11:26, Robert Rothenberg wrote:

 I think that there is a problem using the Makefile.PL with Test::Prereqs 
 and
 similar modules.

 When I run prereqs_ok(), I get the following error:

 _get_prereqs: Error loading Makefile.PL: Can't call method
 load_all_extensions on an undefined value at
 /usr/local/share/perl/5.10.1/Module/Install.pm line 206, DATA line 4267.
 BEGIN failed--compilation aborted at ./Makefile.PL line 4, DATA line 
 4267.

 What leads you to suspect that this is anything to do with 
 Module::Install::Catalyst?

 I'd have guessed at a bug between Test::Prereqs and Module::Install itself, 
 rather than the Catalyst specific extension..

 It occurs in some of the other modules that do the same thing, such as
 Module::CPANTS::Kwalalitee::Prereq.

I can't figure out form a brief look at the source what might be causing it,
and asked on this list in case anyone else has come across the problem.


___
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] Changing Formhandler field-type/widget based on Catalyst user-role

2012-05-23 Thread will trillich
Short version: How can we toggle field X from being a Select (popup) for
Admin users, to being a Hidden (nothing visible, but the value is
maintained) for Manager users?

Long version:

We have three levels of user-roles (*admins* can do everything,
*managers*can do a lot,
*readonly* can do very little). Admins get to specify user roles for all
users (even other admins), but managers (level two) only get to edit
readonly users and we don't want them to elevate any such users to being
managers (or worse, admins).

package MyApp::Controller::Admin::Person;
#...
$self-form( MyApp::Form::Admin::Person-new( ctx = $c ) );

package MyApp::Form::Admin::Person;
#
sub set_active {
my $self = shift;
$self-inactive(['role'])
unless $self-ctx-user-is_admin;
}

Trying to use ctx so we could pass $c and later test it in the form's
set_active method throws an exception because of ctx being undefined.

package MyApp::Controller::Admin::Person;
#...
unless ( $c-user-is_admin ) {
#   $self-form-inactive(['role']);
#   $self-form-field('role')-widget('hidden');
#   $self-form-field('role')-type('Hidden');
}

So instead we've tried making the field inactive (no apparent effect at
all), switching to a different widget (field completely disappears) or
different type (field completely disappears).

Pointers?

-- 
“Waiting for perfect is never as smart as making progress.”  -- Seth Godin
___
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/