53MKnWboUIKj7JwCqIi6Ym changeset

Changeset353735613466 (b)
ParentNone (a)
ab
0+I have this class, and it works OK:
0+
0+class Term::Curses {
0+    has $.y is rw;
0+    has $.x is rw;
0+
0+    has $!stdscr;
0+
0+
0+    submethod BUILD() {
0+        #setlocale(0, "");
0+
0+        # TODO: use newterm() instead of initscr()?
0+        $!stdscr = initscr();
0+
0+        cbreak();
0+        noecho();
0+        nonl();
0+        intrflush($!stdscr, 0);
0+        keypad($!stdscr, 1);
0+
0+        wrefresh($!stdscr);
0+    }
0+
0+
0+    ...
0+}
0+
0+
0+I'd like to define my own new(), so I can call Term::Curses.new(:!cbreak, :nl) or similar, basically to specify which functions get called at this time. But it doesn't work correctly. Seems that initscr() is getting called, but maybe $!stdscr isn't being set during self.bless()? Can you see what I'm doing wrong?
0+
0+
0+    method new() {
0+        #setlocale(0, "");
0+
0+        # TODO: use newterm() instead of initscr()?
0+        my $stdscr = initscr();
0+
0+        cbreak();
0+        noecho();
0+        nonl();
0+        intrflush($stdscr, 0);
0+        keypad($stdscr, 1);
0+
0+        wrefresh($stdscr);
0+
0+        self.bless(*, :$stdscr);
0+    }
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
--- Revision None
+++ Revision 353735613466
@@ -0,0 +1,48 @@
+I have this class, and it works OK:
+
+class Term::Curses {
+ has $.y is rw;
+ has $.x is rw;
+
+ has $!stdscr;
+
+
+ submethod BUILD() {
+ #setlocale(0, "");
+
+ # TODO: use newterm() instead of initscr()?
+ $!stdscr = initscr();
+
+ cbreak();
+ noecho();
+ nonl();
+ intrflush($!stdscr, 0);
+ keypad($!stdscr, 1);
+
+ wrefresh($!stdscr);
+ }
+
+
+ ...
+}
+
+
+I'd like to define my own new(), so I can call Term::Curses.new(:!cbreak, :nl) or similar, basically to specify which functions get called at this time. But it doesn't work correctly. Seems that initscr() is getting called, but maybe $!stdscr isn't being set during self.bless()? Can you see what I'm doing wrong?
+
+
+ method new() {
+ #setlocale(0, "");
+
+ # TODO: use newterm() instead of initscr()?
+ my $stdscr = initscr();
+
+ cbreak();
+ noecho();
+ nonl();
+ intrflush($stdscr, 0);
+ keypad($stdscr, 1);
+
+ wrefresh($stdscr);
+
+ self.bless(*, :$stdscr);
+ }