xamplr 1.9.0 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,18 +1,20 @@
1
- # xamplr
1
+ # xamplr-gen
2
2
 
3
- xamplr is a set of software tools that supports development of ruby applications.
3
+ xamplr-gen is part of a set of software tools that supports development of ruby applications.
4
4
 
5
- It consists of three gems hosted on gem cutter, source code on
6
- github.
5
+ It consists of three gems hosted on gemcutter, source code on github.
7
6
 
8
- * xamplr-pp -- this is a pure ruby pull parser
9
- * xamplr -- this is the xampl runtime
10
- * xamplr-gen -- this is the code generator
7
+ * [xamplr-pp](http://github.com/hutch/xamplr-pp) -- this is a pure ruby pull parser
8
+ * [xamplr](http://github.com/hutch/xamplr) -- this is the xampl runtime
9
+ * [xamplr-gen](http://github.com/hutch/xamplr-gen) -- this is the code generator
11
10
 
12
11
  There is an additional fourth github repository containing
13
12
  examples and documentation that will be coming soon.
14
13
 
15
- Yes, that means that there's no documentation. And no examples. I agree, this is a very bad situation.
14
+ Yes, that means that there's no documentation. And no examples. I agree,
15
+ this is a very bad situation.
16
+
17
+ For more information, see [the xampl page on xampl.com](http://xampl.com/so/xampl/), and/or [the weblog 'So.'](http://xampl.com/so/)
16
18
 
17
19
  ## Installation:
18
20
 
@@ -20,6 +22,12 @@ Yes, that means that there's no documentation. And no examples. I agree, this is
20
22
 
21
23
  This will install all three gems.
22
24
 
25
+ NOTE: if you have installed hutch-xamplr or hutch-xamplr-pp then
26
+ you should uninstall them. For some reason, in certain circumstances,
27
+ these might be loaded or partially loaded when trying to use xampl.
28
+ If you don't you'll experience strange exceptions with hutch-xamplr
29
+ or hutch-xamplr-pp on the stack trace.
30
+
23
31
 
24
32
  ## License:
25
33
 
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 1
3
3
  :minor: 9
4
- :patch: 0
4
+ :patch: 1
5
5
  :build:
@@ -1,2 +1,22 @@
1
- -- use the libxml form of escape attrs (look for apos)
1
+
2
+ -- use nokogiri, libxml, then xamplr-pp if installed
3
+ -- type experiments
4
+ -- mark the repo with creation parameters (so we don't loose them. We
5
+ are setting *defaults* and then using the *defaults* to re-open a
6
+ repo -- this is clearly wrong if the defaults are changed, or the
7
+ persister types are deliberately mixed (which is an intended thing
8
+ to support and was *really* handy in Java)
9
+ -- support conversions between types:
10
+ - fs -> tokyo (no loss of information)
11
+ - tokyo -> fs (currently all indexing will be lost)
12
+ - fs, tokyo -> in-memory (well, no, won't do this)
13
+ -- read-through support, especially handy for in-memory. Makes sense for
14
+ fs and tokyo repos
15
+ -- tokyo tyrant persisters
16
+ -- add NO-CACHE to tokyo persisters (theory is that they cache at a certain
17
+ level (below object level) and that this will allow sharing of the DB a
18
+ little better -- still don't know about multiple writers to the same repo...
19
+ can tyrant help here.
20
+ -- mongo, and a couple of others might be interesting
21
+ -- what about SQL dbs? Maybe an SQL or DataMapper version??
2
22
 
@@ -0,0 +1,150 @@
1
+ x rubytypes.rb:class Class
2
+ rubytypes.rb:class Object
3
+ rubytypes.rb:class Hash
4
+ rubytypes.rb:class Struct
5
+ rubytypes.rb:class Array
6
+ rubytypes.rb:class Exception
7
+ rubytypes.rb:class String
8
+ rubytypes.rb:class Symbol
9
+ rubytypes.rb:class Range
10
+ rubytypes.rb:class Regexp
11
+ rubytypes.rb:class Time
12
+ rubytypes.rb:class Date
13
+ rubytypes.rb:class Integer
14
+ rubytypes.rb:class Float
15
+ rubytypes.rb:class Rational
16
+ rubytypes.rb:class Complex
17
+ rubytypes.rb:class TrueClass
18
+ rubytypes.rb:class FalseClass
19
+ x rubytypes.rb:class NilClass
20
+
21
+ require 'yaml'
22
+ require 'date'
23
+
24
+ def fmttime(t)
25
+ tz = "Z"
26
+ # from the tidy Tobias Peters <t-peters@gmx.de> Thanks!
27
+ unless t.utc?
28
+ utc_same_instant = t.dup.utc
29
+ utc_same_writing = Time.utc(t.year,t.month,t.day,t.hour,t.min,t.sec,t.usec)
30
+ difference_to_utc = utc_same_writing - utc_same_instant
31
+ if (difference_to_utc < 0)
32
+ difference_sign = '-'
33
+ absolute_difference = -difference_to_utc
34
+ else
35
+ difference_sign = '+'
36
+ absolute_difference = difference_to_utc
37
+ end
38
+ difference_minutes = (absolute_difference/60).round
39
+ tz = "%s%02d:%02d" % [ difference_sign, difference_minutes / 60, difference_minutes % 60]
40
+ end
41
+ standard = t.strftime( "%Y-%m-%d %H:%M:%S" )
42
+ standard += ".%06d" % [t.usec] if t.usec.nonzero?
43
+ standard += " %s" % [tz]
44
+ standard
45
+ end
46
+
47
+ def rep(h)
48
+ h.each do | k, v |
49
+ puts "#{ k }: #{ v }/#{ v.class }"
50
+ end
51
+ end
52
+
53
+ class Play
54
+ def initialize(x)
55
+ @x = x
56
+ end
57
+ def to_s
58
+ "#<Play:#{ object_id }> :: x: #{ @x }/#{ @x.class }"
59
+ end
60
+ end
61
+
62
+ def go
63
+ h={}
64
+ h['time'] = Time.now
65
+ #h['date'] = Date.now
66
+ h['datetime'] = DateTime.now
67
+ h['int'] = 10
68
+ h['bigint'] = 1234567890987654321
69
+ h['float'] = 1.23
70
+ h['play'] = Play.new(Time.now)
71
+
72
+
73
+ rep(h)
74
+
75
+ y = YAML.dump(h)
76
+ puts "YAML...."
77
+ puts y
78
+ puts "....YAML"
79
+
80
+ hh = YAML.load(y)
81
+ rep(hh)
82
+
83
+
84
+ puts
85
+ puts
86
+ puts 'play a little....'
87
+
88
+ parser = YAML::Syck::Parser.new
89
+ ss = YAML.dump(Time.now)
90
+
91
+ puts "this should come back as a time object"
92
+ tt = parser.load( ss )
93
+ puts "tt: #{ tt }/#{ tt.class }"
94
+ puts "ss : [[#{ ss }]]"
95
+
96
+
97
+
98
+ puts "try to reproduce the effect"
99
+ #sss = Time.now.to_yaml
100
+ #sss = "--- #{ Time.now }\n"
101
+
102
+ sss = "--- 2009-12-31 09:57:32.810439 -05:00\n"
103
+ puts "sss: [[#{ sss }]]"
104
+ ttt = parser.load( sss )
105
+ puts "ttt: #{ ttt }/#{ ttt.class } <<<--- should be a Time"
106
+
107
+ sss = "--- 2009-12-31 09:57:32 -05:00\n"
108
+ puts "sss: [[#{ sss }]]"
109
+ ttt = parser.load( sss )
110
+ puts "ttt: #{ ttt }/#{ ttt.class } <<<--- should be a Time"
111
+
112
+ sss = "--- #{ Time.now }\n"
113
+ puts "sss: [[#{ sss }]]"
114
+ ttt = parser.load( sss )
115
+ puts "ttt: #{ ttt }/#{ ttt.class } <<<--- should be a Time"
116
+
117
+
118
+ puts
119
+ puts
120
+ puts
121
+
122
+ p = Play.new(Time.now)
123
+ puts p.to_s
124
+ pp = p.to_yaml
125
+ puts "pp: [[#{ pp }]]"
126
+ ppp = parser.load(pp)
127
+ puts ppp.to_s
128
+
129
+ begin
130
+ puts "what if it isn't yaml?"
131
+ x = parser.load("hello world")
132
+ puts "x: [[#{x}]]/#{ x.class }"
133
+ x = parser.load("1234567890987654321")
134
+ puts "x: [[#{x}]]/#{ x.class }"
135
+ x = parser.load(Time.now.to_s)
136
+ puts "x: [[#{x}]]/#{ x.class }"
137
+ x = parser.load("2009-12-31 09:57:32 -05:00")
138
+ puts "x: [[#{x}]]/#{ x.class }"
139
+ x = parser.load(fmttime(Time.now))
140
+ puts "x: [[#{x}]]/#{ x.class } <<< uses the fmttime thing, should be a Time"
141
+ rescue => e
142
+ puts e
143
+ puts e.backtrace
144
+ end
145
+
146
+
147
+ end
148
+
149
+ go
150
+
@@ -92,10 +92,8 @@ module Xampl
92
92
  setup_parse(filename, tokenise_content, is_realising)
93
93
  element, ignore = parse_element
94
94
  return element
95
- rescue Exception => e
96
- puts "trouble parsing file: '#{filename}'"
97
- puts "Exception: #{e}"
98
- raise
95
+ rescue => e
96
+ raise RuntimeError, "trouble parsing file: '#{filename}' -- #{ e }", e.backtrace
99
97
  end
100
98
  end
101
99
 
@@ -108,10 +106,8 @@ module Xampl
108
106
  setup_parse_string(string, tokenise_content, is_realising)
109
107
  element, ignore = parse_element(nil, target)
110
108
  return element
111
- rescue Exception => e
112
- puts "trouble parsing string: '#{string}'"
113
- puts "Exception: #{e}"
114
- raise
109
+ rescue => e
110
+ raise RuntimeError, "trouble parsing string: '#{string}' -- #{ e }", e.backtrace
115
111
  end
116
112
  end
117
113
 
@@ -140,6 +136,9 @@ module Xampl
140
136
  klass_name = "{#{namespace}}#{name}"
141
137
  klasses = FromXML.registered(klass_name)
142
138
  if (0 == klasses.size) then
139
+ # The class has not been registered (either it was never generated, or it was never loaded)
140
+ # puts "#{ __FILE__ }:#{ __LINE__ } [#{__method__}] @@by_ns_tag: #{ @@by_ns_tag.inspect }"
141
+ # puts "#{ __FILE__ }:#{ __LINE__ } [#{__method__}] @@by_tag: #{ @@by_tag.inspect }"
143
142
  xml_text = XMLText.new
144
143
  xml_text.build(self)
145
144
  xml_text = parent.note_adding_text_content(xml_text, @is_realising)
@@ -263,8 +262,10 @@ TODO -- can these ever happen?
263
262
  child = element.note_add_child(child, @is_realising) if element
264
263
  child.append_to(element) if element and child
265
264
  when XMLText then
265
+ #TODO -- get rid of this puts
266
266
  puts "UNRECOGNISED Well-formed XML: #{child.to_s[0..25]}..."
267
267
  else
268
+ #TODO -- get rid of this puts
268
269
  puts "WHAT IS THIS??? #{child.class.name}"
269
270
  end
270
271
  end
@@ -358,11 +359,11 @@ TODO -- can these ever happen?
358
359
  #describe_current_element_type
359
360
 
360
361
  #TODO -- get rid of this, it is for debugging only
362
+ #TODO -- really?
361
363
  begin
362
364
  okay = @reader.read
363
365
  rescue => e
364
- puts "WHAT???? #{ e }"
365
- raise e
366
+ raise RuntimeError, "WHAT?? -- #{ e }", e.backtrace
366
367
  end
367
368
 
368
369
  @just_opened_an_element = start_element?
@@ -23,7 +23,6 @@ module Xampl
23
23
  end
24
24
 
25
25
  def Xampl.register_persister_kind(klass)
26
- #puts "#{ __FILE__ }:#{ __LINE__ } [#{__method__}] REGISTER: #{ klass.kind } --> #{ klass }"
27
26
  @@persister_kinds[klass.kind] = klass
28
27
  end
29
28
 
@@ -98,8 +97,6 @@ module Xampl
98
97
  end
99
98
 
100
99
  unless @@persister then
101
- # puts "CREATE PERSISTER #{name}, format: #{format}, kind: #{kind}"
102
- # puts "#{ __FILE__ }:#{ __LINE__ } [#{__method__}] kinds available: #{ @@persister_kinds.keys.inspect }"
103
100
  @@persister = @@persister_kinds[kind].new(name, format)
104
101
  if (nil != name) then
105
102
  @@known_persisters[name] = @@persister
@@ -209,8 +206,7 @@ module Xampl
209
206
  # we get here if the transaction block finishes early
210
207
  if exception then
211
208
  # the early finish was caused by an exception
212
- puts "ROLLBACK(#{__LINE__}):: #{exception}" if rollback and @@verbose_transactions
213
- raise exception
209
+ raise RuntimeError, "ROLLBACK(#{__LINE__}):: #{exception}", exception.backtrace
214
210
  else
215
211
  # How could we have arrived at this point???
216
212
  # Well, I don't know all the reasons, but the ones I do know are:
@@ -296,10 +292,10 @@ module Xampl
296
292
  if 0 == @changed.size then
297
293
  @changed = original_changed
298
294
 
299
- if exception then
300
- puts "ROLLBACK(#{__LINE__}):: #{exception}"
301
- print exception.backtrace.join("\n") if exception
302
- end
295
+ #if exception then
296
+ # puts "ROLLBACK(#{__LINE__}):: #{exception}"
297
+ # print exception.backtrace.join("\n") if exception
298
+ #end
303
299
 
304
300
  #no change so don't bother with rollback
305
301
  # if rollback then
@@ -307,11 +303,11 @@ module Xampl
307
303
  # end
308
304
  @@persister = initial_persister
309
305
  else
310
- puts "CHANGED COUNT: #{@changed.size}"
306
+ #puts "CHANGED COUNT: #{@changed.size}"
311
307
  @changed = original_changed
312
308
 
313
- puts "ROLLBACK(#{__LINE__}) #{exception}" if rollback
314
- print exception.backtrace.join("\n")
309
+ #puts "ROLLBACK(#{__LINE__}) #{exception}" if rollback
310
+ #print exception.backtrace.join("\n")
315
311
  Xampl.rollback
316
312
 
317
313
  @@persister = initial_persister
@@ -362,14 +358,14 @@ module Xampl
362
358
  if 0 == @changed.size then
363
359
  @changed = original_changed
364
360
 
365
- puts "ROLLBACK(#{__LINE__})" if rollback
361
+ #puts "ROLLBACK(#{__LINE__})" if rollback
366
362
  Xampl.rollback if rollback
367
363
  @@persister = initial_persister
368
364
  else
369
- puts "CHANGED COUNT: #{@changed.size}"
365
+ #puts "CHANGED COUNT: #{@changed.size}"
370
366
  @changed = original_changed
371
367
 
372
- puts "ROLLBACK(#{__LINE__})" if rollback
368
+ #puts "ROLLBACK(#{__LINE__})" if rollback
373
369
  Xampl.rollback
374
370
 
375
371
  @@persister = initial_persister
@@ -420,10 +416,6 @@ module Xampl
420
416
  @@persister.sync
421
417
  end
422
418
 
423
- def Xampl.version(stream)
424
- @@persister.version(stream) if nil != @@persister
425
- end
426
-
427
419
  def Xampl.sync_all
428
420
  @@known_persisters.each{ | name, persister | persister.sync }
429
421
  end
@@ -25,6 +25,7 @@ module Xampl
25
25
  @write_count = 0
26
26
  @total_write_count = 0
27
27
  @last_write_count = 0
28
+ @last_cache_hits = 0
28
29
  @total_sync_count = 0
29
30
  @total_rollback_count = 0
30
31
  @rolled_back = false
@@ -146,12 +147,6 @@ module Xampl
146
147
  end
147
148
  end
148
149
 
149
- def version(stream)
150
- raise XamplException.new(:unimplemented)
151
- # catch(:refuse_to_version) do
152
- # end
153
- end
154
-
155
150
  def write(xampl)
156
151
  raise XamplException.new(:unimplemented)
157
152
  end
@@ -230,6 +225,7 @@ module Xampl
230
225
  end
231
226
 
232
227
  def sync
228
+ @last_sync_time = Time.now
233
229
  #raise XamplException.new(:live_across_rollback) if @rolled_back
234
230
  begin
235
231
  # puts "#{ __FILE__ }:#{ __LINE__ } [#{__method__}] SYNC changed: #{@changed.size}" if 0 < @changed.size
@@ -273,8 +269,10 @@ module Xampl
273
269
  @total_cache_hits = @total_cache_hits + @cache_hits
274
270
  @total_sync_count = @total_sync_count + 1
275
271
 
276
- @read_count = 0
272
+ @last_cache_hits = @cache_hits
277
273
  @last_write_count = @write_count
274
+ @cache_hits = 0
275
+ @read_count = 0
278
276
  @write_count = 0
279
277
 
280
278
  self.sync_done()
@@ -284,6 +282,7 @@ module Xampl
284
282
  busy(false)
285
283
  # puts "#{ __FILE__ }:#{ __LINE__ } [#{__method__}] **** SYNCING IS FALSE"
286
284
  @syncing = false
285
+ @last_sync_time = Time.now - @last_sync_time
287
286
  end
288
287
  end
289
288
 
@@ -306,10 +305,10 @@ module Xampl
306
305
  end
307
306
 
308
307
  def print_stats
309
- printf("SYNC:: TOTAL cache_hits: %d, reads: %d, writes: %d\n",
310
- @total_cache_hits, @total_read_count, @total_write_count)
311
- printf(" cache_hits: %d, reads: %d, last writes: %d\n",
312
- @cache_hits, @read_count, @last_write_count)
308
+ printf("SYNC[%s]:: TOTAL cache_hits: %d, reads: %d, writes: %d\n",
309
+ self.name, @total_cache_hits, @total_read_count, @total_write_count)
310
+ printf(" cache_hits: %d, reads: %d, writes: %d, time: %fms \n",
311
+ @last_cache_hits, @read_count, @last_write_count, @last_sync_time)
313
312
  printf(" syncs: %d\n", @total_sync_count)
314
313
  printf(" changed count: %d (%d)\n", count_changed, @changed.size)
315
314
  @changed.each do |thing, ignore|
@@ -83,7 +83,6 @@ module Xampl
83
83
  end
84
84
 
85
85
  def write_to_cache(xampl)
86
- # puts "WRITE TO CACHE (#{xampl})"
87
86
  return Xampl.store_in_cache(@cache, xampl, self) { xampl }
88
87
  end
89
88
 
@@ -92,9 +91,10 @@ module Xampl
92
91
  if xampl then
93
92
  if target and target != xampl then
94
93
 
95
- puts "#{File.basename(__FILE__)} #{__LINE__} CACHE CONFLICT:: klass: #{ klass }, pid: #{ pid }, target: #{ target }, cached: #{ xampl }"
96
- dump(@cache)
97
- caller(0).each { | trace | puts " #{trace}"}
94
+ #TODO -- report this better
95
+ #puts "#{File.basename(__FILE__)} #{__LINE__} CACHE CONFLICT:: klass: #{ klass }, pid: #{ pid }, target: #{ target }, cached: #{ xampl }"
96
+ #dump(@cache)
97
+ #caller(0).each { | trace | puts " #{trace}"}
98
98
 
99
99
  target.invalidate
100
100
  raise XamplException.new(:cache_conflict)
@@ -147,12 +147,12 @@ module Xampl
147
147
  #puts "ABSTRACT_READ[#{__LINE__}]:: klass: #{klass} pid: #{pid} target: #{target}"
148
148
  xampl = realise(representation, target)
149
149
  return nil unless xampl
150
- rescue Exception => e
151
- puts "FAILED TO READ -- persister: #{name} klass: #{klass} pid: #{pid} target: #{target}"
152
- puts "Exception: #{e}"
153
- print e.backtrace.join("\n")
154
- #sleep 10
155
- raise e
150
+ rescue => e
151
+ raise RuntimeError, "FAILED TO READ -- persister: #{name} klass: #{klass} pid: #{pid} target: #{target}\n#{ e }", e.backtrace
152
+ #puts "FAILED TO READ -- persister: #{name} klass: #{klass} pid: #{pid} target: #{target}"
153
+ #puts "Exception: #{e}"
154
+ #print e.backtrace.join("\n")
155
+ #raise e
156
156
  end
157
157
 
158
158
  # puts "#{File.basename(__FILE__)} #{__LINE__} STORE IN CACHE:: xampl: #{xampl }, persister: #{ self }"