1# -*- tcl -*-
2# # ## ### ##### ######## #############
3# (C) 2009 Andreas Kupries
4
5# @@ Meta Begin
6# Package tcl::chan::null 1
7# Meta as::author {Andreas Kupries}
8# Meta as::copyright 2009
9# Meta as::license BSD
10# Meta description Re-implementation of Memchan's null
11# Meta description channel. Based on Tcl 8.5's channel
12# Meta description reflection support. Exports a single
13# Meta description command for the creation of new
14# Meta description channels. No arguments. Result is the
15# Meta description handle of the new channel.
16# Meta platform tcl
17# Meta require TclOO
18# Meta require tcl::chan::events
19# Meta require {Tcl 8.5}
20# @@ Meta End
21
22# # ## ### ##### ######## #############
23
24package require Tcl 8.5
25package require TclOO
26package require tcl::chan::events
27
28# # ## ### ##### ######## #############
29
30namespace eval ::tcl::chan {}
31
32proc ::tcl::chan::null {} {
33    return [::chan create {write} [null::implementation new]]
34}
35
36oo::class create ::tcl::chan::null::implementation {
37    superclass ::tcl::chan::events ; # -> initialize, finalize, watch
38
39    method initialize {args} {
40	my allow write
41	next {*}$args
42    }
43
44    # Ignore the data in most particulars. We do count it so that we
45    # can tell the caller that everything was written. Null device.
46
47    method write {c data} {
48	return [string length $data]
49    }
50}
51
52# # ## ### ##### ######## #############
53package provide tcl::chan::null 1
54return
55