Re: [Catalyst] get the path to the home
On Fri, Sep 28, 2007 at 03:30:23PM +0300, Octavian Rasnita wrote: Hi, I have a I18N module in my Catalyst application and I want to get the path to the home directory of the application. Is it possible to get it without hard codding it in that module? The module is: package MyApp::I18N::ro; Assuming you can access to $c, I think this is what you want: $c-path_to(’’) It's described in 'perldoc Catalyst' and mentioned in 'perldoc Catalyst::Plugin::ConfigLoader' -- Chisel Wright e: [EMAIL PROTECTED] w: http://www.herlpacker.co.uk/ Any fool can use a computer. Many do. ___ 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] get the path to the home
On 09/28/2007 07:30 AM, Octavian Rasnita wrote: Hi, I have a I18N module in my Catalyst application and I want to get the path to the home directory of the application. Is it possible to get it without hard codding it in that module? $c-path_to() -- Peter Karman . [EMAIL PROTECTED] . http://peknet.com/ ___ 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] get the path to the home
The __FILE__ compile-time constant may be of some use.. You should be able to get the directory of the current module by doing something like: package MyApp::I18N::foo; use strict; sub get_my_dir { my ($dir) = __FILE__ =~ m!^ (.*) / [^/]+ !x; return $dir; } Of course, if you wanted to do that from a subclass or so you'd probably have to get the package of the object by ref($self) || $self, turn that into a file name and then look it up in %INC to find the location of the object. Mark On Friday 28 September 2007 3:46 pm, Octavian Rasnita wrote: From: Chisel Wright [EMAIL PROTECTED] On Fri, Sep 28, 2007 at 03:30:23PM +0300, Octavian Rasnita wrote: Hi, I have a I18N module in my Catalyst application and I want to get the path to the home directory of the application. Is it possible to get it without hard codding it in that module? The module is: package MyApp::I18N::ro; Assuming you can access to $c, I think this is what you want: $c-path_to(’’) It's described in 'perldoc Catalyst' and mentioned in 'perldoc Catalyst::Plugin::ConfigLoader' -- Chisel Wright Thank you but I know that. However, I have just the following module which is not a controller or a model or a view: # Copy/paste from Catalyst::Plugin::I18N: #MyApp/I18N/de.pm package MyApp::I18N::de; use base 'MyApp::I18N'; our %Lexicon = ( 'Hello Catalyst' = 'Hallo Katalysator' ); 1; So I don't have access to $c. Does this mean that I will need to hard code the path to the home directory? Here is what I want to do: I want to create a site in more languages, and it is simple to use a .po file for translating short strings, however I also need to display a few pages with pretty large descriptions, and I think I can avoid using a database for this. Instead of using .po files I want to use perl modules like ro.pm, de.pm and so on, and in those files I want to define the translations as: our %lexicon = ( 'term' = 'translation', 'another term' = get_file('another_term', ); sub get_file { my $file = shift; # read that file and return its content } I will keep those files in directories named with the language names like de, ro, en, fr, and they will be placed in MyApp/lib/MyApp/I18N directory (where the .pm or .po files should be also placed. And I want to know if there is a way of getting that folder name without hard codding it. Thanks. Octavian ___ 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/ ___ 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] get the path to the home
MyApp-path_to() 2007/9/28, Octavian Rasnita [EMAIL PROTECTED]: Hi, I have a I18N module in my Catalyst application and I want to get the path to the home directory of the application. Is it possible to get it without hard codding it in that module? The module is: package MyApp::I18N::ro; Thank you. Octavian ___ 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/ ___ 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] get the path to the home
Have you looked at FindBin? use FindBin; from the docs: EXPORTABLE VARIABLES $Bin - path to bin directory from where script was invoked $Script - basename of script from which perl was invoked $RealBin - $Bin with all links resolved $RealScript - $Script with all links resolved Sergio On 9/28/07, Octavian Rasnita [EMAIL PROTECTED] wrote: Hi, I have a I18N module in my Catalyst application and I want to get the path to the home directory of the application. Is it possible to get it without hard codding it in that module? The module is: package MyApp::I18N::ro; Thank you. Octavian ___ 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/ ___ 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/