Helma logo
main list history

Version 10 by tobi on 18. February 2008, 11:26

17<em>Update:</em> I added the file <code>patch-for-emacs-integration.diff</code> which Massimiliano sent to me; he "added a few bits, namely set/get/push/popenv and the multiline input mode, needed for EmacsEmacs integration." Maybe this helps other Emacs users, too.
18integration." Maybe this helps other Emacs users, too.

Version 9 by tobi on 18. February 2008, 11:25

17<em>Update:</em> I added the file <code>patch-for-emacs-integration.diff</code> which Massimiliano sent to me; he "added a few bits, namely set/get/push/popenv and the multiline input mode, needed for Emacs
18integration." Maybe this helps other Emacs users, too.
19

Version 8 by tobi on 19. January 2008, 12:53

172Please note that the e-mail address is not changed in the database, yet. To achieve this one could has to add a <code>res.commit()</code> at this point. After invalidating the application – which of course could can be done in HopRepl as well by invoking <code>app.clearCache()</code> – the new value will also be displayed when its property is requestedstill persistent:
178  REPL> dataRoot.creator.email
179  somebody@somewhere.com

Version 7 by tobi on 19. January 2008, 12:47

172Please note that the e-mail address is not changed in the database, yet. To achieve this one could add a <code>res.commit()</code> at this point. After invalidating the application – which of course could be done in HopRepl as well by invoking <code>app.clearCache()</code> – the new value will also be displayed when its property is requested.:
174  REPL> res.commit()
175  REPL> repl.back(); repl.back() // Back to the application's context
176  [Application antville]
177  REPL> clearCache()
178

Version 6 by tobi on 19. January 2008, 12:40

172Unfortunately, this version of HopRepl being absolutely Please note that the e-mail address is not changed in alpha stage cannot change the database value of propertiesdatabase, yet. At least I currently did not succeed in doing soTo achieve this one could add a <code>res.commit()</code> I cannot even predict if at this will point. After invalidating the application – which of course could be possible done in that manner.HopRepl as well by invoking <code>app.clearCache(.)?</code> – the new value will also be displayed when its property is requested.
174However,That's it so far. maybe Maybe this first attempt will grow and if anyone is interested in picking up the pieces, please contact me via the helma-dev mailing list.
179* <s>Allow modifications of properties to trickle down to the database</s> Works with <code>res.commit()</code>

Version 5 by tobi on 17. January 2008, 16:27

169  REPL> email = "somebody@somewhere.com"

Version 4 by tobi on 17. January 2008, 16:21

1=== Introduction
2
178* Allow modifications of properties to trickle down to the database

Version 3 by tobi on 17. January 2008, 16:17

5<small>Note: Chris Langreiter was here years ago already when he published <a href="http://www.langreiter.com/space/HopShell">HopShell</a>., I don't know what happened to it right nowa REPL written in Rebol.</small>

Version 2 by tobi on 17. January 2008, 16:15

  • Changed tags to Tobi, REPL, shell, introspection
3HopRepl actually is similar to HopShell <a href="https://dev.helma.org/trac/helma/browser/apps/helmaTools/trunk/Global/helma.shell.js">Helma Shell</a> with the tiny difference that it does not run in a browser window but in a terminal environment (aka command line).
5<small>Note: Chris Langreiter was here years ago already when he published <a href="http://www.langreiter.com/space/HopShell">HopShell</a>. I don't know what happened to it right now.</small>
6
16=== Installation and setupAnd Setup
18First, move the two files attached to this wiki as repl.zip and repl.jar into you your application directory. I recommend the manage application because it already provides some interesting objects to explore.
171However, maybe this first attempt will grow and if anyone is interested in picking up the pieces, please contact me via the helma-dev mailing list. // *tobi*
172
173=== To Do
174
175* Eat those nasty java.lang.Nullpointer exceptions (could be something with entering Java class context)
176
177// *tobi*

Version 1 by tobi on 17. January 2008, 15:00

  • Set tags to shell, introspection, Tobi, REPL
1Inspired by Massimiliano Mirra's <a href="http://hyperstruct.net/projects/mozrepl">MozRepl</a> project I quickly coded a similar tool, for now dubbed HopRepl.
3HopRepl actually is similar to HopShell with the tiny difference that it does not run in a browser window but in a terminal environment (aka command line).
4
5The four letters <a href="http://en.wikipedia.org/wiki/REPL">REPL</a> actually are in fact used synonymously for a shell.
6
7Thus, you can enter simple commands to inspect and manipulate Helma space. And commands are of course JavaScript statements!
8
9This is an alpha version, ie. you will get excepctions, stuck and not always what you expected.
10
11Thanks to Robert and Hannes for their help; it wouldn't be even alpha without them.
12
13Here's what you can do with it:
14
15=== Installation and setup
16
17First, move the two files attached to this wiki as repl.zip and repl.jar into you application directory. I recommend the manage application because it already provides some interesting objects to explore.
18
19<% this.attachments %>
20
21To be sure that the HopRepl code is really compiled into the application a Helma restart won't hurt.
22
23Now you can start the HopRepl server by navigating to the "repl" action in your browser. In my case the location is http://localhost:8080/manage/repl
24
25There you will see one simple line saying "HopREPL server (stopped)" followed by two links "Start" and "Restart".
26
27Click on the "Start" link and your HopRepl should be started. Simultaneously, the link will change to "Stop" and the port number will be displayed in brackets.
28
29(If not you might check if anything else is running behind that port on your computer already. Use the application property replPort to change the port number.)
30
31=== Using HopRepl
32
33Let's check if you can connect from the command line shell to the HopRepl server by entering
34
35  telnet localhost 1234
36
37(Be sure to use the desired port number if you should have changed it in the previous step.)
38
39If everyhing goes well HopRepl should welcome you with a short message and the REPL prompt:
40
41  Hello! This is HopRepl Alpha (c) 2008 Tobi Schäfer
42  REPL>
43
44After the prompt you can enter any JavaScript statement you like. It will be (R)ead, (E)valuated and the result will be (P)rinted in your terminal. Finally, the (L)oop starts again with your next input. That's the generic principle behind REPL.
45
46  REPL> new Date
47  Thu Jan 17 2008 12:21:57 GMT+0100 (CET)
48  REPL> Math
49  [object Math]
50  REPL> this
51  [object GlobalObject]
52
53There is one special object added to the JavaScript as defined by Rhino and Helma. It is called repl and acts as a helper object providing methods to make navigating and exploring the namespace more convenient.
54
55  REPL> repl
56  HopREPL server (port 1234)
57
58To get a clue where in Helma space you are right now you can use the whereAmI() method:
59
60  REPL> repl.whereAmI()
61  [object GlobalObject]
62
63The look() method prints a list of all available properties and methods in the current context:
64
65  REPL> repl.look()
66  this.Repl = [function]
67  this.Server = [function]
68  this.Thread = [function]
69  this.Xml = {class helma.scripting.rhino.extensions.XmlObject}
70  this.app = {class helma.framework.core.ApplicationBean}
71  this.appStat = [function]
72  this.checkAddress = [function]
73  this.checkAuth = [function]
74  this.createAddressFilter = [function]
75  ...
76  this.req = {class helma.framework.RequestBean}
77  this.res = {class helma.framework.ResponseBean}
78  this.root = {class helma.main.Server}
79  this.scheduler = [function]
80  this.session = {class helma.framework.core.SessionBean}
81  this.skin_macro = [function]
82  this.sortByName = [function]
83  this.sortProps = [function]
84
85For convenience you don't have to always type in "this" to access a property or a method. HopRepl provides all available properties of the current context as global variables:
86
87  REPL> res
88  [Response]
89  REPL> session
90  [Anonymous Session]
91  REPL> skin_macro
92  function skin_macro(par) {
93      if (par && par.name) {
94        renderSkin(par.name);
95      }
96  }
97
98The enter() method changes the context to another object:
99
100  REPL> repl.enter(root)
101  helma.main.Server@d03ed2
102  REPL> repl.look()
103  this.application = undefined
104  this.applications = {class [Ljava.lang.Object;}
105  this.appsHome = {class java.io.File}
106  this.appsProperties = undefined
107  this.checkAppManager = [function]
108  this.class = {class java.lang.Class}
109  this.dbHome = {class java.io.File}
110  ...
111  REPL> repl.enter(checkAppManager)
112  function checkAppManager() {/*
113      void checkAppManager(int)
114  */}
115
116To get back to the previous context the back() method is at hand:
117
118  REPL> repl.back()
119  helma.main.Server@d03ed2
120
121And the home() method brings you even further back, straight up to the top-level context:
122
123  REPL> repl.home()
124  [object GlobalObject]
125
126If you should have enough of tinkering with HopRepl the quit() method closes the connection to the server:
127
128  REPL> repl.quit()
129  Connection closed by foreign host.
130
131=== Getting Nifty
132
133Of course you can also call methods, not only enter their contextes. Here's a more elaborated example of using HopRepl to stop an application:
134
135  REPL> repl.home()
136  [object GlobalObject]
137  REPL> repl.enter(root)
138  helma.main.Server@d03ed2
139  REPL> repl.enter(getApplication("test"))
140  [Application test]
141  REPL> isRunning()
142  true
143  REPL> stop()
144  REPL> isRunning()
145  false
146
147Further manipulation is possible, too. Let's change a HopObject's property:
148
149  REPL> repl.home()
150  [object GlobalObject]
151  REPL>> repl.enter(root)
152  helma.main.Server@d03ed2
153  REPL> repl.enter(getApplication("antville"))
154  [Application antville]
155  REPL> repl.enter(dataRoot)
156  HopObject Site 14
157  REPL> repl.enter(creator)
158  HopObject p3k
159  REPL> repl.look()
160  this.comments = [object]
161  this.created = [object]
162  this.email = nobody@nowhere.com
163  this.files = [object]
164  ...
165  REPL> email = somebody@somewhere.com
166  somebody@somewhere.com
167
168Unfortunately, this version of HopRepl being absolutely in alpha stage cannot change the database value of properties. At least I currently did not succeed in doing so. I cannot even predict if this will be possible in that manner...?
169
170However, maybe this first attempt will grow and if anyone is interested in picking up the pieces, please contact me via the helma-dev mailing list. // *tobi*