5 use 5.008; # too much magic in here to include perl 5.6
8 unshift @INC, "modules/override"; # Use our own versions of various modules (e.g. YAML).
9 push @INC, "modules/fallback"; # Only use our own versions of modules if there's no system version.
13 use Devel::REPL 1.002001;
14 use Term::ReadLine::Perl::Bind; # use sane key binding for rxvt users
17 SL::LxOfficeConf->read;
19 my $login = shift || $::lx_office_conf{console}{login} || 'demo';
20 my $history_file = $::lx_office_conf{console}{history_file} || '/tmp/lxoffice_console_history.log'; # fallback if users is not writable
21 my $autorun = $::lx_office_conf{console}{autorun};
23 # will be configed eventually
24 my @plugins = qw(History LexEnv Colors MultiLine::PPI FancyPrompt PermanentHistory AutoloadModules);
26 my $repl = Devel::REPL->new;
27 $repl->load_plugin($_) for @plugins;
28 $repl->load_history($history_file);
30 $repl->print("trying to auto login as '$login'...");
31 $repl->print($repl->eval("lxinit '$login'"));
33 my $result = $repl->eval($autorun);
34 $repl->print($result->message) if ref($result) eq 'Devel::REPL::Error';
41 use CGI qw( -no_xhtml);
45 use SL::Helper::DateTime;
50 # this is a cleaned up version of am.pl
51 # it lacks redirection, some html setup and most of the authentication process.
52 # it is assumed that anyone with physical access and execution rights on this script
53 # won't be hindered by authentication anyway.
57 die 'need login' unless $login;
61 $::lxdebug = LXDebug->new;
62 $::locale = Locale->new($::lx_office_conf{system}->{language});
63 $::cgi = CGI->new qw();
65 $::auth = SL::Auth->new;
67 die 'cannot reach auth db' unless $::auth->session_tables_present;
69 $::auth->restore_session;
71 require "bin/mozilla/common.pl";
73 die "cannot find user $login" unless %::myconfig = $::auth->read_user($login);
75 $::form->{login} = $login; # normaly implicit at login
77 die "cannot find locale for user $login" unless $::locale = Locale->new($::myconfig{countrycode});
80 return "logged in as $login";
83 # these function provides a load command to slurp in a lx-office module
84 # since it's seldomly useful, it's not documented in help
87 $module =~ s/[^\w]//g;
88 require "bin/mozilla/$module.pl";
92 require Module::Reload;
93 Module::Reload->check();
95 return "modules reloaded";
107 ./scripts/console [login]
111 help - zeigt diese Hilfe an.
112 lxinit 'login' - lädt das Lx-Office Environment für den User 'login'.
113 reload - lädt modifizierte Module neu.
114 pp DATA - zeigt die Datenstruktur mit Data::Dumper an.
115 quit - beendet die Konsole
118 # load 'module' - läd das angegebene Modul, d.h. bin/mozilla/module.pl und SL/Module.pm.
122 local $Data::Dumper::Indent = 2;
123 local $Data::Dumper::Maxdepth = 2;
124 local $Data::Dumper::Sortkeys = 1;
125 Data::Dumper::Dumper(@_);
134 scripts/console - Lx Office Console
139 > help # displays a brief documentation
143 Users of Ruby on Rails will recognize this as a perl reimplementation of the
144 rails scripts/console. It's intend is to provide a shell environment to the
145 lx-office internals. This will mostly not interest you if you just want to do
146 your ERP stuff with lx-office, but will be invaluable for those who wish to
147 make changes to lx-office itself.
151 You can do most things in the console that you could do in an actual perl
152 script. Certain helper functions will aid you in debugging the state of the
157 Named after the rails pretty print gem, this will call Data::Dumper on the
158 given C<DATA>. Use it to see what is going on.
160 Currently C<pp> will set the Data::Dumper depth to 2, so if you need a
161 different depth, you'll have to change that. A nice feature would be to
162 configure that, or at least to be able to change it at runtime.
164 =head2 lxinit C<login>
166 Login into lx-office using a specified login. No password will be required, and
167 security mechanisms will mostly be inactive. form, locale, myconfig will be
172 Attempts to reload modules that changed since last reload (or inital startup).
173 This will mostly work just fine, except for Moose classes that have been made
174 immutable. Keep in mind that existing objects will continue to have the methods
175 of the classes they were created with.
179 - Reload on immutable Moose classes is buggy.
180 - Logging in more than once is not supported by the program, and thus not by
181 the console. It seems to work, but strange things may happen.
185 Configuration of this script is located in:
187 config/lx_office.conf
188 config/lx_office.conf.default
190 See there for interesting options.
194 Sven Schöling <s.schoeling@linet-services.de>