emilbarton has asked for the wisdom of the Perl Monks concerning the following question:

Hello, while I'm preparing a new revision of my musical program Csgrouper -- which goes pretty well now -- I'm wondering how I could simplify all the startup steps.

As Csgrouper requires an application directory, with several subdirectories and files, I first set up a complicated way of launching the application; in front of this complication (Csgrouper could be started from within its directory or not, with or without an initial project file, etc.) I decided finally not to manage different scenarios and to require Csgrouper to be started from witin its directory. But I'm not satisfied with that either.

Could anyone please redirect me to some judicious or even standard ways of handling these startup questions?

Thanks in advance.

https://github.com/emilbarton/Csgrouper

  • Comment on How to manage correctly a (Tk) application startup?

Replies are listed 'Best First'.
Re: How to manage correctly a (Tk) application startup?
by tobyink (Canon) on Jul 15, 2013 at 16:40 UTC

    You could use chdir in combination with FindBin to switch to the application directory early on; then it doesn't matter where they start it from.

    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
Re: How to manage correctly a (Tk) application startup?
by Anonymous Monk on Jul 15, 2013 at 23:56 UTC

    File::HomeDir + File::ShareDir => File::UserConfig

    Maybe add in File::FindLib? Path::Class, Path::Tiny??

    #!/usr/bin/perl -- use Path::Class; use constant THISFILE => file( __FILE__ )->absolute->stringify; use constant THISDIR => file( THISFILE )->dir->stringify; use constant THISCWD => dir()->absolute->resolve; use lib dir( THISDIR(), 'csgrouper_lib' )->stringify; use strict; use warnings; use autodie qw/ chdir /; chdir THISDIR(); Main( @ARGV ); exit( 0 );
Re: How to manage correctly a (Tk) application startup?
by emilbarton (Scribe) on Jul 16, 2013 at 05:49 UTC
    Thanks for these answers, it runs well with:
    use Cwd; $ARGV[0] = cwd()."/$ARGV[0]" unless $ARGV[0] =~ /^(\/.*)$/ ; # Abs. use FindBin qw($RealBin); chdir "$RealBin/.."; use lib "$RealBin";
    and some minimal file check.