File tree Expand file tree Collapse file tree 1 file changed +12
-11
lines changed Expand file tree Collapse file tree 1 file changed +12
-11
lines changed Original file line number Diff line number Diff line change @@ -138,27 +138,28 @@ can serve this role. This means you can expose libraries that work on handles
138
138
by writing a class like this:
139
139
140
140
class FooHandle is repr('CPointer') {
141
- has $!initialized;
142
-
143
141
# Here are the actual NativeCall functions.
144
142
sub Foo_init() returns FooHandle is native("foo") { * }
145
143
sub Foo_free(FooHandle) is native("foo") { * }
144
+ sub Foo_query(FooHandle, Str) returns int8 is native("foo") { * }
145
+ sub Foo_close(FooHandle) returns int8 is native("foo") { * }
146
146
147
147
# Here are the methods we use to expose it to the outside world.
148
- method new() {
148
+ method new {
149
149
Foo_init();
150
- $!initialized = True;
151
150
}
152
- method free() {
153
- if $!initialized {
154
- Foo_free(self);
155
- $!initialized = False; # prevent double frees
156
- }
151
+
152
+ method query(Str $stmt) {
153
+ Foo_query(self, $stmt);
154
+ }
155
+
156
+ method close {
157
+ Foo_close(self);
157
158
}
158
159
159
160
# Free data when the object is garbage collected.
160
- method DESTROY() {
161
- self.free ;
161
+ submethod DESTROY {
162
+ Foo_free( self) ;
162
163
}
163
164
}
164
165
You can’t perform that action at this time.
0 commit comments