 |
| Recent blog posts: | |
 |
| They have birthday today: | |
 |
| Forums: | | |
 |
| Discuss: | |
 |
| Recent forum topics: | |
 |
| Recent forum comments: | |
 |
| Модератор: | |
 |
Friday, 20 February 2009
|
| Re: Temporal and purity Ruud H.G. van Tol 20:32:32 |
| | David Green wrote:
I don't like dates just starting at midnight because I've run into too many awkward cases where $time < $date doesn't do what you mean because it assumes 0:00:00 when you meant 23:59:59. I'd rather have dates becomes time-ranges. And not all midnights exist, because time can jump from 23:59:59 to 01:00:00. (DST)
-- Ruud
|
| | Add comment |
|
| Temporal and purity (was: Re: IO, Trees, and Time/Date) Timothy S. Nelson 20:19:36 |
| | Just to clear up ahead of time, the consensus both here and on IRC seemed to be that in the core, we put a basic Temporal::Instant object that about powerful enough to deal with: - localtime/gmtime functionality - ctime, mtime, etc, in stat() - nanoseconds or whatever needed for (I think) alarm() and things
There is bucketloads of other functionality that could be implemented, and I've included a few of what I consider to be the most important (ie. make it work with operators), but we hope to leave most other stuff to CPAN. Even the naming of months, etc, can be left to CPAN. I've got a few hooks in there to deal with things that CPAN will want, but hopefully that's all.
On Thu, 19 Feb 2009, Martin D Kealey wrote:
On Wed, 18 Feb 2009, Timothy S. Nelson wrote: I'll try and design an API that does what DateTime does, but: 1. Uses more variables, of which I expect the getters and setters to be Please let's NOT have setters on "time" objects. They're a source of subtle bugs in such client code AND having mutable objects means you can't use them in otherwise pure code. (See the separate thread on immutability and purity.) Rather, let's have immutable time "values", and methods which return other "values" where various computations (*1) have been applied. Provide constructors which take the Y/M/D/h/m/s/dst_now/dst_rule tuple. I followed the bits about the computations, and I think I see what you're saying about the constructor, but I don't know what you mean by 'immutable time "values"'. Could you expand on this a bit?
And please let's not have any implied "default" timezone. That's not to say it has to be difficult or cumbersome, just explicit, perhaps something like one of these: my &localtime = DateTime::Gregorian.localize( :host_default ); my &localtime = DateTime::Gregorian.localize( :user_env ); my &localtime = DateTime::Gregorian.localize( :http_client(%http_client_headers) ); my &localtime = DateTime::Gregorian.localize( :db_server($odbc_handle) ); my &gmtime = DateTime::Gregorian.localize( :utc ); my &swatch = DateTime::Gregorian.localize( :tz('Europe/Geneva'), :no_dst ); Actually, I admit I'd love to get rid of gmtime and localtime altogether, while keeping the functionality. It seems to me that each is really a constructor with a different default timezone. Likewise I'd like to get rid of the time() function.
I snipped the comments about the complexity of calculations. I figure that for most purposes, people don't want the complexity, and as long as CPAN can supply something that implements the same role, I'm happy to leave it to them.
--------------------------------------------------------------------- | Name: Tim Nelson | Because the Creator is, | | E-mail: wayland@wayland.id.au | I am | ---------------------------------------------------------------------
----BEGIN GEEK CODE BLOCK---- Version 3.12 GCS d+++ s+: a- C++$ U+++$ P+++$ L+++ E- W+ N+ w--- V- PE(+) Y+>++ PGP->+++ R(+) !tv b++ DI++++ D G+ e++>++++ h! y- -----END GEEK CODE BLOCK-----
|
| | 3 answer | Add comment |
|
| r25459 - docs/Perl6/Spec/S32-setting-library Guest 17:22:41 |
| | Author: autarch Date: 2009-02-20 15:22:41 +0100 (Fri, 20 Feb 2009) New Revision: 25459
Modified: docs/Perl6/Spec/S32-setting-library/Temporal.pod Log: method Str returns Str seems rather redundant and repetitive
Modified: docs/Perl6/Spec/S32-setting-library/Temporal.pod =================================================================== --- docs/Perl6/Spec/S32-setting-library/Temporal.pod 2009-02-20 09:48:25 UTC (rev 25458) +++ docs/Perl6/Spec/S32-setting-library/Temporal.pod 2009-02-20 14:22:41 UTC (rev 25459) @@ -127,7 +127,7 @@ method iso8601 () returns Str { [ self.hour, self.minute, self.fractional-second ].join(':') } - method Str returns Str { self.iso8601() }; + method Str { self.iso8601() }; multi method infix:{'<=>'} (Temporal::Time $self, Temporal::Time $other) { $self.hour <=> $other.hour @@ -161,7 +161,7 @@ ~ $minutes.truncate.fmt('%02d'); } - method Str returns Str { self.iso8601 } + method Str { self.iso8601 } } This is called an I<observance> because it represents the state of a
|
| | Add comment |
|
| Exegesis 7/format() question Timothy S. Nelson 07:20:17 |
| | Hi all. According to S29, the Perl 5 format() function is obsolete, and it says "See Exegesis 7". According to Exegesis 7, there will be a Form.pm which implements similar functionality, but has to be "use"d. My questions are: 1. Is the Form.pm module discussed anywhere in the specs? 2. This seems to imply that the Form.pm module will be included as part of the standard Perl distribution, but not "use"d by default. Is this the case? I presume this is also true of the IO roles. Is there somewhere a list of all the modules that will be part of the standard Perl6 distro?
--------------------------------------------------------------------- | Name: Tim Nelson | Because the Creator is, | | E-mail: wayland@wayland.id.au | I am | ---------------------------------------------------------------------
----BEGIN GEEK CODE BLOCK---- Version 3.12 GCS d+++ s+: a- C++$ U+++$ P+++$ L+++ E- W+ N+ w--- V- PE(+) Y+>++ PGP->+++ R(+) !tv b++ DI++++ D G+ e++>++++ h! y- -----END GEEK CODE BLOCK-----
|
| | 2 answer | Add comment |
|
| r25452 - docs/Perl6/Spec/S32-setting-library Guest 04:42:25 |
| | Author: wayland Date: 2009-02-20 02:42:25 +0100 (Fri, 20 Feb 2009) New Revision: 25452
Modified: docs/Perl6/Spec/S32-setting-library/Temporal.pod Log: Minor syntax fix
Modified: docs/Perl6/Spec/S32-setting-library/Temporal.pod =================================================================== --- docs/Perl6/Spec/S32-setting-library/Temporal.pod 2009-02-19 21:37:47 UTC (rev 25451) +++ docs/Perl6/Spec/S32-setting-library/Temporal.pod 2009-02-20 01:42:25 UTC (rev 25452) @@ -88,7 +88,7 @@ method iso8601 () returns Str { [ self.year, self.month, self.date ].join('-') }; - method infix:{'~'} return Str { self.iso8601 }; + method Str { self.iso8601 }; multi method infix:{'<=>'} (Temporal::Date $self, Temporal::Date $other) { $self.year <=> $other.year
|
| | Add comment |
|
| r25405 - docs/Perl6/Spec/S32-setting-library Guest 03:05:22 |
| | Author: wayland Date: 2009-02-19 08:47:26 +0100 (Thu, 19 Feb 2009) New Revision: 25405
Modified: docs/Perl6/Spec/S32-setting-library/Temporal.pod Log: Improved Temporal (previously DateTime) stuff a bit
Modified: docs/Perl6/Spec/S32-setting-library/Temporal.pod =================================================================== --- docs/Perl6/Spec/S32-setting-library/Temporal.pod 2009-02-19 07:45:07 UTC (rev 25404) +++ docs/Perl6/Spec/S32-setting-library/Temporal.pod 2009-02-19 07:47:26 UTC (rev 25405) @@ -66,35 +66,25 @@ =head1 Roles -=head2 Time and Date roles +=head2 Temporal::Date -=head3 Date +You probably want to use the Temporal::Instant object instead. -You probably want to use the DateTime object instead. +role Temporal::Date { + has Int $.year; + has Int $.month; + has Int $.day; # Day of month + has Int $.dayofweek; + has Int $.era; # BC, AD, etc, depending on locale + has Str $.defaultformat; # A CLDR-formatted string, for use with toString(); -role Date { - has Calendar $.calendar; # Gregorian, Secular, Julian, etc - has NumberName $.year; - has NumberName $.month; - has NumberName $.dayofmonth; - has NumberName $.dayofweek; - has NumberName $.dayofyear; - has NumberName $.dayofquarter; - has NumberName $.quarter; - has NumberName $.era; # 'Common', 'Christian', etc - has Str $.defaultformat; + method toString($format => $.defaultformat); - method toString($format); - method isLeapYear(); + multi method Temporal::Instant infix:<+>(Temporal: ate $self, Temporal::Time $other); + multi method Temporal::Instant infix:<+>(Temporal: ate $self, Temporal::Duration $other); - multi method DateTime infix:<+>(Date $self, Time $other); - multi method DateTime infix:<+>(Date $self, Duration $other); - - multi method infix:{'<=>'}(Date $self, Date $other); - multi method infix:{'<=>'}(Date $self, Duration $other); - - method get(Str $type, Str $of); - method last(Str $type, Str $of); + multi method infix:{'<=>'}(Temporal::Date $self, Temporal::Date $other); + multi method infix:{'<=>'}(Temporal::Date $self, Temporal::Duration $other); } Example: @@ -102,15 +92,7 @@ $date = new Date('2002/01/01'); $date.month.name(); # January $date.month.name('short'); # Jan -$date.get('day', of => 'year'); -$date = new Date('2002/01/01'); -$date.convertcalendar('Chinese'); -$date.year.name(); # Snake - -A fair bit of initialisation of the NumberNames for day of the week and month will need to -be done. - $format will naturally need to allow for eras. =over @@ -123,60 +105,57 @@ =back -=head3 Time +=head2 Temporal::Time -You probably want to use the DateTime object instead. +You probably want to use the Temporal::Instant object instead. -role Time { +role Temporal::Time { has $.hour; has $.minute; has $.second; method toString($format?); # This can't be right; how do we specify this - multi method infix:{'<=>'}(Time $self, Time $other); - multi method infix:{'<=>'}(Time $self, Duration $other); + multi method infix:{'<=>'}(Temporal::Time $self, Temporal::Time $other); + multi method infix:{'<=>'}(Temporal::Time $self, Temporal::Duration $other); } When created, recognises "today" as a possibility. -=head1 Classes - -=head2 Time and Date classes - -=head3 NumberName - - class NumberName { +role Temporal::Timezone { has $.number; - method name($format?) { - ... - } - } - -=head3 Timezone - -role Timezone { - has $.number; - method name($format); method is_dst(); } -=head3 DateTime +role Temporal::Subsecond { + has $.nanosecond; +} -class DateTime does Date does Time does Timezone { +=head1 Classes + +=head2 Temporal::Timezone + +=head2 Temporal::Instant + +class Temporal::Instant + does Temporal::Date + does Temporal::Time + does Temporal::Timezone + does Temporal::Subsecond +{ has $.locale; has $.parser; has $.formatter; # Only for output formats - multi method DateTime infix:<+>(DateTime $self, Duration $other); + multi method Temporal::Instant infix:<+>(Temporal::Instant $self, Duration $other); - multi method infix:<->(DateTime $self, Duration $other); - multi method infix:<->(DateTime $self, Duration $other); + multi method infix:<->(Temporal::Instant $self, Duration $other); + multi method infix:<->(Temporal::Instant $self, Duration $other); - multi method infix:{'<=>'}(DateTime $self, DateTime $other); - multi method infix:{'<=>'}(DateTime $self, Duration $other); + multi method infix:{'<=>'}(Temporal::Instant $self, Temporal::Instant $other); + multi method infix:{'<=>'}(Temporal::Instant $self, Duration $other); method new(:$String); method truncate(Str $to); @@ -215,13 +194,20 @@ =back -=head3 Duration +=head2 Temporal::Duration -=head3 Repetition +class Temporal::Duration + does Temporal::Date + does Temporal::Time + does Temporal::Subsecond +{ +} +=head2 Temporal::Recurring + This class specifies when a repetitive action (eg. a cron job) happens. -class DateTime::Recurring { +class Temporal::Recurring { ... }
|
| | 6 answers | Add comment |
|
| Spec reorganisation Timothy S. Nelson 02:44:54 |
| | Hi all. I'd like to suggest a slight reorganisation within the specs.
The first thing I've observed is that, in defining the IO stuff, and adding in the Tree and DateTime stuff, is that we're getting a lot of non-IO stuff in there.
I'm aware that the numbering and ordering of the specs is based on the chapters in the Camel book. It seems like a lot of this stuff that I'm working on would really belong under 32: Standard Modules. But there's a lot of this stuff, and, while the Camel book just gives an overview of each module, we want to specify the API.
I'm not suggesting here that we specify the interfaces to all the modules listed in the Camel book, or anything like that. Instead, I'm suggesting that the S32 space be used for documenting the objects that we don't seem to be able to get away from.
My thought is that, at the moment, these are: - The function groups documented in S29 - The IO, Tree, and DateTime stuff being drafted in S16
After looking through the Phlanx project (which lists 100 or so top perl modules), and the list in the Camel book, I can only see one or two other things we might eventually need, and these can be worried about later.
Anyway, my suggestion is that a folder called S32-standard-modules be created in the Spec directory, and that within this folder, the following files be created from the specified sources: - Tree.pod -- S16 - DateTime.pod -- S16 (needs lots of work) - IO.pod -- S16 - Most of the stuff from the S29 "Function Packages", in separate files
This would leave S29 free to be solely a list of the functions that do not need to have a package specified when called, and can in most cases simply specify what standard library functions they call.
It would also leave S16-IO free to deal with things that are not specific to the object(s).
Thoughts?
--------------------------------------------------------------------- | Name: Tim Nelson | Because the Creator is, | | E-mail: wayland@wayland.id.au | I am | ---------------------------------------------------------------------
----BEGIN GEEK CODE BLOCK---- Version 3.12 GCS d+++ s+: a- C++$ U+++$ P+++$ L+++ E- W+ N+ w--- V- PE(+) Y+>++ PGP->+++ R(+) !tv b++ DI++++ D G+ e++>++++ h! y- -----END GEEK CODE BLOCK-----
|
| | 8 answers | Add comment |
|
| [Slight OT] DBD/DBIx::Chart need patent protection, know any contacts
? Dean Arnold 02:10:31 |
| | (Sorry if this is OT, but I'm hoping someone can point me in the right direction)
Someone has just alerted me to the following patent attempt by our friends at IBM:
Data Plotting Extension for Structured Query Language (http://www.freepatentsonline.com/y2008/0215554.html)
Given that DBD::Chart predates the filing by at least 7 years (in fact, you can still get a version from CPAN from 2002, and I think BackPAN may have stuff from 2000/2001), I'd like to make sure this thing gets killed. Does anyone know an open source patent holding group, or someplace I can submit prior art claims ?
TIA, Dean Arnold Presicient Corp.
|
| | 1 answer | Add comment |
Thursday, 19 February 2009
|
| r25451 - docs/Perl6/Spec Guest 22:23:21 |
| | Author: hinrik Date: 2009-02-19 22:37:47 +0100 (Thu, 19 Feb 2009) New Revision: 25451
Modified: docs/Perl6/Spec/S29-functions.pod Log: [S29] fix Pod errors
Modified: docs/Perl6/Spec/S29-functions.pod =================================================================== --- docs/Perl6/Spec/S29-functions.pod 2009-02-19 21:16:16 UTC (rev 25450) +++ docs/Perl6/Spec/S29-functions.pod 2009-02-19 21:37:47 UTC (rev 25451) @@ -682,6 +682,8 @@ These functions are exported into the default namespace +=over + =item all -- see S32-setting-library/Container.pod =item any -- see S32-setting-library/Container.pod @@ -744,6 +746,8 @@ =item zip -- see S32-setting-library/Container.pod +=back + =head2 Non-default Functions These functions which existed in perl5 still exist, but are not part of the default @@ -944,6 +948,8 @@ Not sure whether these are exported by default or not. Also, many may no longer exist; if so, they should be entered in the "Obsolete" section. +=over + =item Signal-related alarm @@ -1023,6 +1029,8 @@ wait wantarray +=back + =head1 Additions Please post errors and feedback to perl6-language. If you are making
|
| | Add comment |
Wednesday, 18 February 2009
|
| r25371 - docs/Perl6/Spec Guest 22:24:27 |
| | Author: wayland Date: 2009-02-18 04:30:33 +0100 (Wed, 18 Feb 2009) New Revision: 25371
Modified: docs/Perl6/Spec/S16-io.pod Log: S16: Redid things in terms of trees, at least somewhat.
Modified: docs/Perl6/Spec/S16-io.pod =================================================================== --- docs/Perl6/Spec/S16-io.pod 2009-02-17 21:05:38 UTC (rev 25370) +++ docs/Perl6/Spec/S16-io.pod 2009-02-18 03:30:33 UTC (rev 25371) @@ -204,21 +204,6 @@ the $.locale, or the undefined value at end of file, or if there was an error (in the latter case C<$!> is set). -=item our List multi method lines (IO $handle is export; - -=item our List multi lines (Str $filename); - -Returns all the lines of a file as a (lazy) List regardless of context. -See also C<slurp>. - -=item our Item multi method slurp (IO $handle: *%opts) is export; - -=item our Item multi slurp (Str $filename, *%opts); - -Slurps the entire file into a Str or Buf regardless of context. -(See also C<lines>.) Whether a Str or Buf is returned depends on -the options. - =back =head2 IO::Writeable::Encoded @@ -314,19 +299,6 @@ =back -=head2 IO::FileDescriptor - -This role indicates that this object actually represents an open file -descriptor in the os level. - -=over - -=item method int fileno() - -File descriptors are always native integers, conforming to C89. - -=back - =head2 IO::Closeable This role indicates that this object can be closed. @@ -350,26 +322,17 @@ =head2 IO::Socket -role IO::Socket { +role IO::Socket { + has %.options; ... } +Accessing the %.options would on Unix be done with getsockopt/setsockopt. + =over -=item socket +=item pair -=item IO.setsockopt - -=item IO.shutdown - -(should IO::Socket.close() call shutdown, instead of having a different name?) - -=item IO.accept - -=item IO.bind - -=item Socket.pair - our List of IO method pair(Int $domain, Int $type, Int $protocol) A wrapper for socketpair(2), returns a pair of IO objects representing the @@ -381,18 +344,89 @@ =back -=head1 Filehandles, files, and directories +=head2 IO::Listening -=over 4 +=item open -=item IO.fcntl + method open() -Available only as a handle method. + Does a bind() and a listen(). -=item IO.ioctl +=item accept -Available only as a handle method. + method IO::Socket accept() +=head2 Tree Roles and Classes + +To support the filesystem, it is also useful to define some generic tree roles, which +could equally well be used for XML or LDAP as well as filesystem representation. However, +while the roles are generic, the comments and documentation in this section refers +specifically to filesystems. + +=head3 Tree::Name + + class Tree::Name { + has $.namespace; + has $.prefix; + + # Call this for stringifying + method fullname() + } + + fullname for XML does "$namespace prefix" + +=head3 Tree::Node + +This should be an ancestor role to filesystems, their elements, their attributes, and the +like. + + role Tree::Node does Array { + has Tree::Name $.name; # would usually be File or Directory on a filesystem + has $.ownerNode; # This is the IO::FileSystem + has $.rootNode; This is the root of the filesystem + has $.parent; # Another Tree::Node + has @.children handles <Array List Container>; # This is all the child notes + has $.path is ro; # Accessor does a getpath + has $.depth is ro; # depth from $ownerNode + + method infix:<===>(...) + method infix:<==>(...) + multi method *infix:</>(Tree::Node @nodes: Matcher $test); + multi method postfix:<//>(Tree::Node @parents: Matcher $test); + method path(Str $.quitcriteria); # This allows the path call to quit eg. when it + # gets to the filesystem root, instead of the overall root + } + +Array operations on this are entirely capable of moving files and directories, + +=head3 Tree + + role Tree does Tree::Node { + has Tree::Node $root; # The root directory + has Tree::Node $cwn; # The current working directory (node) + } + +=head3 Tree::Element + + role Tree::Element does Tree::Node { + has %.attributes; # This is all the attributes, including Name + has Str $!defaultattributename; + method postcircumfix:<{ }>($selector, $node(s)); # Accesses stuff in %attributes + method pathelement(); + } + +=head3 Tree::Attribute + + role Tree::Attribute does Tree::Node { + has $.value; + + method pathelement(); + } + +=head1 Filehandles, files, and directories + +=over 4 + =item IO.name The C<.name> method returns the name of the file/socket/uri the handle @@ -442,40 +476,37 @@ =item IO.truncate +=item IO.fcntl + +Available only as a handle method. + =back =head2 IO::FileSystem This reads directories, deletes filesystem entries, creates links, and the like. -class IO::FileSystem does IO::Streamable { - has IO::FileSystemEntry $.cwd; # Current working directory - has IO::FileSystemEntry $.basepath; # The Unix mount point, or Windows drive letter, or whatever - has Str $.type; # ext3, ntfs, vfat, reiserfs, etc +class IO::FileSystem does IO::Streamable does Tree { + has Str $.fstype; # ext3, ntfs, vfat, reiserfs, etc has Str $.illegal_chars; # ie. /\x0 has Int $.max_path; ... } +It inherits $cwn and $root from Tree. + =over 4 =item glob -Returns FileSystemEntry objects +Returns FSNode objects =item find -Returns FileSystemEntry objects +Returns FSNode objects =item link -=item lstat - -Returns a stat buffer. If the lstat succeeds, the stat buffer evaluates -to true, and additional file tests may be performed on the value. If -the stat fails, all subsequent tests on the stat buffer also evaluate -to false. - =item mkdir =item IO::Dir::open EXPR @@ -518,11 +549,10 @@ =back -=head2 IO::FilesystemEntry +=head2 IO::FSNode -class IO::FileSystemEntry { - has Str $path; - has IO::FileSystemEntryACL @.acls; +class IO::FSNode does Tree::Node { + has Array of IO::FSNodeACL @.ACLs; ... } @@ -621,100 +651,33 @@ if $filename.TEST e,:x) {...} -=item chown - - our Int multi chown ($uid = -1, $gid = -1, *@files) - -Changes the owner (and group) of a list of files. The first -two elements of the list must be the numeric uid and gid, in -that order. A value of -1 in either position is interpreted by -most systems to leave that value unchanged. Returns the number -of files successfully changed. - - $count = chown $uid, $gid, ’foo’, ’bar’; - chown $uid, $gid, @filenames; - -On systems that support C<fchown>, you might pass file handles -among the files. On systems that don’t support C<fchown>, passing -file handles produces a fatal error at run time. - -Here’s an example that looks up nonnumeric uids in the passwd -file: - - $user = prompt "User: "; - $pattern = prompt "Files: "; - - ($login,$pass,$uid,$gid) = getpwnam($user) - or die "$user not in passwd file"; - - @ary = glob($pattern); # expand filenames - chown $uid, $gid, @ary; - -On most systems, you are not allowed to change the ownership of -the file unless you’re the superuser, although you should be -able to change the group to any of your secondary groups. On -insecure systems, these restrictions may be relaxed, but this -is not a portable assumption. On POSIX systems, you can detect -this condition this way: - - use POSIX qw(sysconf _PC_CHOWN_RESTRICTED); - $can_chown_giveaway = not sysconf(_PC_CHOWN_RESTRICTED); - -=item chmod LIST -X<chmod> X<permission> X<mode> - -Changes the permissions of a list of files. The first element of the -list must be the numerical mode, which should probably be an octal -number, and which definitely should I<not> be a string of octal digits: -C<0o644> is okay, C<0644> is not. Returns the number of files -successfully changed. - - $cnt = chmod 0o755, 'foo', 'bar'; - chmod 0o755, @executables; - $mode = '0644'; chmod $mode, 'foo'; # !!! sets mode to --w----r-T - $mode = '0o644'; chmod $mode, 'foo'; # this is better - $mode = 0o644; chmod $mode, 'foo'; # this is best - -=item stat - -=item IO.stat - -Returns a stat buffer. If the lstat succeeds, the stat buffer evaluates -to true, and additional file tests may be performed on the value. If -the stat fails, all subsequent tests on the stat buffer also evaluate -to false. - =item realpath method Str realpath(); Gets the real path to the object, resolving softlinks/shortcuts, etc -=item parent +=item === operator - method IO::FileSystemEntry parent(); + method infix:<===>(Str $filename); -=item isSameFile - - method isSameFile(Str $filename); - Test whether the specified filename is the same file as this file. On a Unix system, this would presumably be done by comparing inode numbers or something. =back -=head2 IO::FileSystemEntryACL +=head2 IO::FSNodeACL This is a basic abstraction; for better control, use the operating-system specific -interfaces [not designed yet], over which this is a thin veneer. +interfaces, over which this is a thin veneer. -class IO::FileSystemEntryACL { +class IO::FSNodeACL { has Str $.type; # "User", "Group", "Everyone", ??? has Str $.id; # username or groupname; unused for $type eq "Everyone" has %.permissions; # Unsupported values may (or may not) throw # UnsupportedPermission when set or read - has IO::FileSystemEntry $.owningObject; + has IO::FSNode $.owningObject; ... } @@ -734,7 +697,8 @@ =item Executeable -Supported on most Unix systems, anyway +Supported on most Unix systems, anyway. Windows should be able to guess when this is +read, and throw an exception if written to. =item Default @@ -743,9 +707,40 @@ =back -The $.owningObject attribute of FileSystemEntryACL shows what the ACL is set on. On a +The $.owningObject attribute of FSNodeACL shows what the ACL is set on. On a Windows system, this can be a parent directory, as permissions are inherited. +=head2 IO::FileNode + + role IO::FileNode does IO::FSNode { +... + } + +=over + +=item our List multi method lines (IO $handle is export; + +=item our List multi lines (Str $filename); + +Returns all the lines of a file as a (lazy) List regardless of context. +See also C<slurp>. + +=item our Item multi method slurp (IO $handle: *%opts) is export; + +=item our Item multi slurp (Str $filename, *%opts); + +Slurps the entire file into a Str or Buf regardless of context. +(See also C<lines>.) Whether a Str or Buf is returned depends on +the options. + +=back + +=head2 IO::DirectoryNode + + role IO::DirectoryNode does IO::FSNode { +... + } + =head2 IO::Socket::TCP class IO::Socket::TCP does IO::Socket does IO::Streamable { @@ -762,12 +757,25 @@ =item has $.LocalPort -=item method Bool open($Listen?); +=item init -If $Listen is 2, it does a listen(), but no connect(). -If $Listen is any other true value, it does a connect() and a listen(). -If $Listen is false, it does a connect(), but no listen(). + method Bool init( + $RemoteHost, $RemotePort, + $LocalHost?, $LocalPort?, + $Blocking?, + $NoOpen? + ); +The creation of the object will also open the connection, unless NoOpen is specified. + +=item open + + method open() + +If it's not an IO::Listening, it does a connect(). + +It's intended for the case where the creation of the object didn't do one. + =item method Int read($buf is rw, Int $length) Does a recv(). @@ -782,25 +790,6 @@ =back -=head2 IO::POSIX - -Indicates that this object can perform standard posix IO -operations. It implies IO::Readable and IO::Writeable. - -=over - -=item method IO dup() - -=item has Bool $.blocking is rw - -=item method Bool flock(:$r, w) - -=item method Bool funlock() - -=item ... - -=back - =head2 IO::Pipe class IO::Pipe does IO::Streamable { @@ -860,12 +849,124 @@ =back +=head1 OS-specific classes + +=head2 Unix + +=head2 IO::FileDescriptor + +This role indicates that this object actually represents an open file +descriptor in the os level. + +=over + +=item method int fileno() + +File descriptors are always native integers, conforming to C89. + +=back + +=head2 IO::FSNode::Unix + +=item chown + + our Int multi chown ($uid = -1, $gid = -1, *@files) + +Changes the owner (and group) of a list of files. The first +two elements of the list must be the numeric uid and gid, in +that order. A value of -1 in either position is interpreted by +most systems to leave that value unchanged. Returns the number +of files successfully changed. + + $count = chown $uid, $gid, ’foo’, ’bar’; + chown $uid, $gid, @filenames; + +On systems that support C<fchown>, you might pass file handles +among the files. On systems that don’t support C<fchown>, passing +file handles produces a fatal error at run time. + +Here’s an example that looks up nonnumeric uids in the passwd +file: + + $user = prompt "User: "; + $pattern = prompt "Files: "; + + ($login,$pass,$uid,$gid) = getpwnam($user) + or die "$user not in passwd file"; + + @ary = glob($pattern); # expand filenames + chown $uid, $gid, @ary; + +On most systems, you are not allowed to change the ownership of +the file unless you’re the superuser, although you should be +able to change the group to any of your secondary groups. On +insecure systems, these restrictions may be relaxed, but this +is not a portable assumption. On POSIX systems, you can detect +this condition this way: + + use POSIX qw(sysconf _PC_CHOWN_RESTRICTED); + $can_chown_giveaway = not sysconf(_PC_CHOWN_RESTRICTED); + +=item chmod LIST +X<chmod> X<permission> X<mode> + +Changes the permissions of a list of files. The first element of the +list must be the numerical mode, which should probably be an octal +number, and which definitely should I<not> be a string of octal digits: +C<0o644> is okay, C<0644> is not. Returns the number of files +successfully changed. + + $cnt = chmod 0o755, 'foo', 'bar'; + chmod 0o755, @executables; + $mode = '0644'; chmod $mode, 'foo'; # !!! sets mode to --w----r-T + $mode = '0o644'; chmod $mode, 'foo'; # this is better + $mode = 0o644; chmod $mode, 'foo'; # this is best + +=item lstat + +Returns a stat buffer. If the lstat succeeds, the stat buffer evaluates +to true, and additional file tests may be performed on the value. If +the stat fails, all subsequent tests on the stat buffer also evaluate +to false. + +=item stat + +=item IO.stat + +Returns a stat buffer. If the lstat succeeds, the stat buffer evaluates +to true, and additional file tests may be performed on the value. If +the stat fails, all subsequent tests on the stat buffer also evaluate +to false. + +=head2 IO::POSIX + +Indicates that this object can perform standard posix IO +operations. It implies IO::Readable and IO::Writeable. + +=over + +=item method IO dup() + +=item has Bool $.blocking is rw + +=item method Bool flock(:$r, w) + +=item method Bool funlock() + +=item ... + +=back + =head1 Unfiled =over 4 =item IO.fileno +=item IO.ioctl + +Available only as a handle method. + =item alarm =item prompt @@ -874,12 +975,8 @@ =item Str.readpipe -=item IO.sysread - =item IO.sysseek -=item IO.syswrite - =back =head1 Removed functions @@ -898,10 +995,22 @@ Gone. (Note: for subsecond sleep, just use sleep with a fractional argument.) +=item IO.shutdown() + +Gone, see IO::Socket.close() + =item socketpair Gone, see Socket.pair +=item IO.sysread + +Gone, see IO::Readable.read() + +=item IO.syswrite + +Gone, see IO::Writeable.read() + =back =head1 Additions
|
| | 4 answer | Add comment |
|
| r25382 - docs/Perl6/Spec Guest 14:16:00 |
| | Author: wayland Date: 2009-02-18 12:16:00 +0100 (Wed, 18 Feb 2009) New Revision: 25382
Modified: docs/Perl6/Spec/S16-io.pod Log: Fixed some things people were complaining about.
Modified: docs/Perl6/Spec/S16-io.pod =================================================================== --- docs/Perl6/Spec/S16-io.pod 2009-02-18 11:11:32 UTC (rev 25381) +++ docs/Perl6/Spec/S16-io.pod 2009-02-18 11:16:00 UTC (rev 25382) @@ -54,6 +54,16 @@ This role provides unbuffered read access to the data stream. +role IO::Readable { + has $.isReadable; + + method Int read($buf is rw, Int $length) +} + +When the $.isReadable is set, it tries to change the readability of the filehandle. This +is not always possible, but can be done in a number of cases. IO::Socket can remove +readability by calling shutdown(), for example. + =over =item method Int read($buf is rw, Int $length) @@ -68,17 +78,22 @@ you're going to need to encode it later, or use "getc" or other IO::Readable::Encoded methods. -=item method Bool is_readable() - -Indicates whether socket is actually opened for reading. Closed sockets -return false. - =back =head2 IO::Writeable This role provides unbuffered write access to the data stream. +role IO::Writeable { + has $.isWriteable; + + method Int write($buf, Int $length) +} + +When the $.isWriteable is set, it tries to change the writeability of the filehandle. +This is not always possible, but can be done in a number of cases. IO::Socket can remove +writeability by calling shutdown(), for example. + =over =item method Int write($buf, Int $length) @@ -92,11 +107,6 @@ encoded data, you should decode it first, or use "print" or other IO::Writeable::Encoded methods. -=item method Bool is_writeable() - -Indicates whether socket is actually opened for writing. Closed sockets -return false. - =back =head2 IO::Seekable @@ -356,6 +366,19 @@ method IO::Socket accept() +=head2 IO::FileDescriptor + +This role indicates that this object actually represents an open file +descriptor in the os level. + +=over + +=item method int fileno() + +File descriptors are always native integers, conforming to C89. + +=back + =head2 Tree Roles and Classes To support the filesystem, it is also useful to define some generic tree roles, which @@ -535,7 +558,7 @@ multi method infix:{'<=>'}(DateTime $self, DateTime $other); multi method infix:{'<=>'}(DateTime $self, Duration $other); - method new(Str $String); + method new(:$String); method truncate(Str $to); method last(Str $type, Str $of); method toString($format?); @@ -548,7 +571,7 @@ =item new - method new(Str $String) # parser defaults to 'strptime' or something similar + method new(Str String) # parser defaults to 'strptime' or something similar | (Str $parser, Str $String) # $parser = 'strptime' | (Str $parser, Int $Epoch) # $parser = 'epoch' | (Str $parser, Str $Timezone?) # $parser = 'today' [unless strptime does this] @@ -596,8 +619,8 @@ =item new - method new(Str $filename, $options?); - method new(Int $fd); + method new(Str filename, $options?); + method new(Int fd); # Read $fobj = new IO::File($filename); @@ -815,12 +838,18 @@ This is called automatically on object creation. -multi method new(@pathelements); # new IO::FSNode('home', 'wayland') -multi method new(String $type, String $path) # new IO::FSNode('Unix', '/home/wayland'); -multi method new(String $path) # new IO::FSNode('/home/wayland'); +multi method new(Array of Str :@pathelements); +multi method new(String type, String path); +multi method new(String path); This last throws an error if "use portable" pragma is used. +Examples: + + $fsnode = new IO::FSNode(pathelements => ['home', 'wayland']); + $fsnode = new IO::FSNode(type => 'Unix', path => '/home/wayland'); + $fsnode = new IO::FSNode(path => '/home/wayland'); + =back =head2 IO::FSNodeACL @@ -916,11 +945,11 @@ =item new - method Bool new( - $RemoteHost, $RemotePort, - $LocalHost?, $LocalPort?, - $Blocking?, - $NoOpen? + method IO::Socket::TCP new( + RemoteHost, RemotePort, + LocalHost, LocalPort, + Blocking, + NoOpen ); The creation of the object will also open the connection, unless NoOpen is specified. @@ -1010,19 +1039,6 @@ =head2 Unix -=head2 IO::FileDescriptor - -This role indicates that this object actually represents an open file -descriptor in the os level. - -=over - -=item method int fileno() - -File descriptors are always native integers, conforming to C89. - -=back - =head2 IO::FSNode::Unix =item chown @@ -1170,7 +1186,7 @@ =item IO.shutdown() -Gone, see IO::Socket.close() +Gone, see IO::Socket.close(), $IO::Readable.isReadable, and $IO::Writeable.isWriteable =item socketpair
|
| | Add comment |
|
| r25373 - docs/Perl6/Spec Guest 13:20:09 |
| | Author: wayland Date: 2009-02-18 06:09:25 +0100 (Wed, 18 Feb 2009) New Revision: 25373
Modified: docs/Perl6/Spec/S16-io.pod Log: S16: Started adding some DateTime stuff, but stopped pending some questions to the mailing list.
Modified: docs/Perl6/Spec/S16-io.pod =================================================================== --- docs/Perl6/Spec/S16-io.pod 2009-02-18 05:06:54 UTC (rev 25372) +++ docs/Perl6/Spec/S16-io.pod 2009-02-18 05:09:25 UTC (rev 25373) @@ -423,26 +423,167 @@ method pathelement(); } -=head1 Filehandles, files, and directories +=head2 Time and Date roles -=over 4 +=head3 Date -=item IO.name +You probably want to use the DateTime object instead. -The C<.name> method returns the name of the file/socket/uri the handle -was opened with, if known. Returns undef otherwise. There is no -corresponding C<name()> function. +role Date { + has Calendar $.calendar; + has NumberName $.year; + has NumberName $.month; + has NumberName $.dayofmonth; + has NumberName $.dayofweek; + has NumberName $.dayofyear; + has NumberName $.dayofquarter; + has NumberName $.quarter; + has NumberName $.era; # 'Common', 'Christian', etc + has Str $.defaultformat; -=item sysopen + method toString($format); + method isLeapYear(); -=item umask + multi method DateTime infix:<+>(Date $self, Time $other); + multi method DateTime infix:<+>(Date $self, Duration $other); -=item utime + multi method infix:<<=>>(Date $self, Date $other); + multi method infix:<<=>>(Date $self, Duration $other); + method get(Str $type, Str $of); + method last(Str $type, Str $of); +} + +Example: + +$date = new Date('2002/01/01'); +$date.month.name(); # January +$date.month.name('short'); # Jan +$date.get('day', of => 'year'); + +$date = new Date('2002/01/01'); +$date.convertcalendar('Chinese'); +$date.year.name(); # Snake + +A fair bit of initialisation of the NumberNames for day of the week and month will need to +be done. + +$format will naturally need to allow for eras. + +=over + +=item + + method toString($format = 'YYYY/MM/DD'); + +$format contains things like YYYY/MM/DD or whatever. + =back +=head3 Time + +You probably want to use the DateTime object instead. + +role Time { + has $.hour; + has $.minute; + has $.second; + + method toString($format?); + # This can't be right; how do we specify this + multi method infix:<<=>>(Time $self, Time $other); + multi method infix:<<=>>(Time $self, Duration $other); +} + +When created, recognises "today" as a possibility. + =head1 Classes +=head2 Time and Date classes + +=head3 NumberName + + class NumberName { + has $.number; + + method name($format?) { + ... + } + } + +=head3 Timezone + +role Timezone { + has $.number; + + method name($format); + method is_dst(); +} + +=head3 DateTime + +class DateTime does Date does Time does Timezone { + has $.locale; + has $.parser; + has $.formatter; # Only for output formats + + multi method DateTime infix:<+>(DateTime $self, Duration $other); + + multi method infix:<->(DateTime $self, Duration $other); + multi method infix:<->(DateTime $self, Duration $other); + + multi method infix:<<=>>(DateTime $self, DateTime $other); + multi method infix:<<=>>(DateTime $self, Duration $other); + + method init(); + method truncate(Str $to); + method last(Str $type, Str $of); + method toString($format?); +} + +All formats are CLDR, although implementations may want to have another set of functions +that use the strftime functions instead. + +=over + +=item init + + method init(Str $String) # parser defaults to 'strptime' or something similar + | (Str $parser, Str $String) # $parser = 'strptime' + | (Str $parser, Int $Epoch) # $parser = 'epoch' + | (Str $parser, Str $Timezone?) # $parser = 'today' [unless strptime does this] + ; + +Tries to parse the date and time specified using $parser. + +If $Epoch is passed in instead, then it interprets the time as being in seconds since the +epoch (which is determined on a system-by-system basis). + +If $parser is 'today', then the current time is gotten. Timezone would be useful for +simulating eg. gmtime(). + +=item truncate + +Can be used to truncate a function to the current day, or whatever. + +=item last + + $date.last('day', of => 'month'); + +=back + +=head3 Duration + +=head3 Repetition + +This class specifies when a repetitive action (eg. a cron job) happens. + +class DateTime::Recurring { +... +} + +Should allow creation from the format that cron uses (ie. */5 * * * * ). + =head2 IO::File This does file input and output. @@ -961,6 +1102,18 @@ =over 4 +=item IO.name + +The C<.name> method returns the name of the file/socket/uri the handle +was opened with, if known. Returns undef otherwise. There is no +corresponding C<name()> function. + +=item sysopen + +=item umask + +=item utime + =item IO.fileno =item IO.ioctl
|
| | 1 answer | Add comment |
|
| r25380 - docs/Perl6/Spec Guest 13:04:41 |
| | Author: wayland Date: 2009-02-18 11:04:41 +0100 (Wed, 18 Feb 2009) New Revision: 25380
Modified: docs/Perl6/Spec/S16-io.pod Log: Fixed .new() methods to have correct name (instead of .init(), like I had)
Modified: docs/Perl6/Spec/S16-io.pod =================================================================== --- docs/Perl6/Spec/S16-io.pod 2009-02-18 09:35:48 UTC (rev 25379) +++ docs/Perl6/Spec/S16-io.pod 2009-02-18 10:04:41 UTC (rev 25380) @@ -535,7 +535,7 @@ multi method infix:{'<=>'}(DateTime $self, DateTime $other); multi method infix:{'<=>'}(DateTime $self, Duration $other); - method init(); + method new(Str $String); method truncate(Str $to); method last(Str $type, Str $of); method toString($format?); @@ -546,9 +546,9 @@ =over -=item init +=item new - method init(Str $String) # parser defaults to 'strptime' or something similar + method new(Str $String) # parser defaults to 'strptime' or something similar | (Str $parser, Str $String) # $parser = 'strptime' | (Str $parser, Int $Epoch) # $parser = 'epoch' | (Str $parser, Str $Timezone?) # $parser = 'today' [unless strptime does this] @@ -594,10 +594,10 @@ =over -=item init +=item new - method init(Str $filename, $options?); - method init(Int $fd); + method new(Str $filename, $options?); + method new(Int $fd); # Read $fobj = new IO::File($filename); @@ -811,15 +811,15 @@ Test whether the specified filename is the same file as this file. On a Unix system, this would presumably be done by comparing inode numbers or something. -=item init +=item new -This is called automatically on object creation; I'm unsure if init is the right name. +This is called automatically on object creation. -multi method init(@pathelements); # new IO::FSNode('home', 'wayland') -multi method init(String $type, String $path) # new IO::FSNode('Unix', '/home/wayland'); -multi method init(String $path) # new IO::FSNode('/home/wayland'); +multi method new(@pathelements); # new IO::FSNode('home', 'wayland') +multi method new(String $type, String $path) # new IO::FSNode('Unix', '/home/wayland'); +multi method new(String $path) # new IO::FSNode('/home/wayland'); -This last throws an error if "use portable" is used. +This last throws an error if "use portable" pragma is used. =back @@ -914,9 +914,9 @@ =item has $.LocalPort -=item init +=item new - method Bool init( + method Bool new( $RemoteHost, $RemotePort, $LocalHost?, $LocalPort?, $Blocking?,
|
| | Add comment |
|
| r25375 - docs/Perl6/Spec Guest 09:29:03 |
| | Author: wayland Date: 2009-02-18 07:29:03 +0100 (Wed, 18 Feb 2009) New Revision: 25375
Modified: docs/Perl6/Spec/S16-io.pod Log: Fixed operator overloading calls.
Modified: docs/Perl6/Spec/S16-io.pod =================================================================== --- docs/Perl6/Spec/S16-io.pod 2009-02-18 06:14:51 UTC (rev 25374) +++ docs/Perl6/Spec/S16-io.pod 2009-02-18 06:29:03 UTC (rev 25375) @@ -447,8 +447,8 @@ multi method DateTime infix:<+>(Date $self, Time $other); multi method DateTime infix:<+>(Date $self, Duration $other); - multi method infix:<<=>>(Date $self, Date $other); - multi method infix:<<=>>(Date $self, Duration $other); + multi method infix:{'<=>'}(Date $self, Date $other); + multi method infix:{'<=>'}(Date $self, Duration $other); method get(Str $type, Str $of); method last(Str $type, Str $of); @@ -491,8 +491,8 @@ method toString($format?); # This can't be right; how do we specify this - multi method infix:<<=>>(Time $self, Time $other); - multi method infix:<<=>>(Time $self, Duration $other); + multi method infix:{'<=>'}(Time $self, Time $other); + multi method infix:{'<=>'}(Time $self, Duration $other); } When created, recognises "today" as a possibility. @@ -532,8 +532,8 @@ multi method infix:<->(DateTime $self, Duration $other); multi method infix:<->(DateTime $self, Duration $other); - multi method infix:<<=>>(DateTime $self, DateTime $other); - multi method infix:<<=>>(DateTime $self, Duration $other); + multi method infix:{'<=>'}(DateTime $self, DateTime $other); + multi method infix:{'<=>'}(DateTime $self, Duration $other); method init(); method truncate(Str $to);
|
| | Add comment |
|
| r25374 - docs/Perl6/Spec Guest 09:14:52 |
| | Author: wayland Date: 2009-02-18 07:14:51 +0100 (Wed, 18 Feb 2009) New Revision: 25374
Modified: docs/Perl6/Spec/S16-io.pod Log: Bits and pieces, but mostly trying to clean up the list of unfiled functions.
Modified: docs/Perl6/Spec/S16-io.pod =================================================================== --- docs/Perl6/Spec/S16-io.pod 2009-02-18 05:09:25 UTC (rev 25373) +++ docs/Perl6/Spec/S16-io.pod 2009-02-18 06:14:51 UTC (rev 25374) @@ -430,7 +430,7 @@ You probably want to use the DateTime object instead. role Date { - has Calendar $.calendar; + has Calendar $.calendar; # Gregorian, Secular, Julian, etc has NumberName $.year; has NumberName $.month; has NumberName $.dayofmonth; @@ -694,9 +694,15 @@ class IO::FSNode does Tree::Node { has Array of IO::FSNodeACL @.ACLs; + has Hash of %.times; ... } +The %times has keys that can be eg. ctime, Modification, and Access (and maybe others on +other operating systems), and the values are all DateTime objects. + +When .path() is implemented, it should return the path that this was opened with. + =over 4 =item IO ~~ :X @@ -805,6 +811,16 @@ Test whether the specified filename is the same file as this file. On a Unix system, this would presumably be done by comparing inode numbers or something. +=item init + +This is called automatically on object creation; I'm unsure if init is the right name. + +multi method init(@pathelements); # new IO::FSNode('home', 'wayland') +multi method init(String $type, String $path) # new IO::FSNode('Unix', '/home/wayland'); +multi method init(String $path) # new IO::FSNode('/home/wayland'); + +This last throws an error if "use portable" is used. + =back =head2 IO::FSNodeACL @@ -1102,20 +1118,6 @@ =over 4 -=item IO.name - -The C<.name> method returns the name of the file/socket/uri the handle -was opened with, if known. Returns undef otherwise. There is no -corresponding C<name()> function. - -=item sysopen - -=item umask - -=item utime - -=item IO.fileno - =item IO.ioctl Available only as a handle method. @@ -1126,10 +1128,16 @@ our Str prompt (Str $prompt) + Should there be an IO::Interactive role? + =item Str.readpipe +=item sysopen + =item IO.sysseek +=item umask + =back =head1 Removed functions @@ -1140,6 +1148,18 @@ Gone, see IO::Endable +=item IO.fileno + +See IO::FileDescriptor + +=item IO.name + +Changed to .path(), but we haven't gotten around to specifying this on all of them. + +The C<.name> method returns the name of the file/socket/uri the handle +was opened with, if known. Returns undef otherwise. There is no +corresponding C<name()> function. + =item pipe Gone, see Pipe.pair @@ -1164,6 +1184,10 @@ Gone, see IO::Writeable.read() +=item utime + +Gone, see %IO::FSNode.times. + =back =head1 Additions
|
| | Add comment |
|
| The use of roles in S16 (Was: Re: r25328 - docs/Perl6/Spec) Daniel Ruoso 08:50:44 |
| | Em S b, 2009-02-14 s 18:01 +0100, Leon Timmermans escreveu:
On Sat, Feb 14, 2009 at 6:38 AM, <pugs-commits@feather.perl6.nl> wrote: +This role implies that the object can be connected to, or listened on. I'm not sure if I really hate or love this. I'm not quite convinced if the use of it anyway. Maybe I'm thinking sideways again, but I haven't thought of "open" as being a method of any IO object, because usually "open" is the thing that gets you an IO Object.
I'd expect the plain "open" to be really a sub (maybe a "is export" method in the generic IO role), that does whatever it needs to do to provide you an IO object, including composing the roles according to the features it supports.
One important thing here, is that the roles are not intended to represent attributes of the object. For instance, IO::Readable and IO::Writeable are not going to be composed depending on the parameters you send to "open", but if you're in a Linux system, it should probably return an object that does IO::Linux26 (which does IO::POSIX[$SomeLevel] does IO::BSD[$Somewhat], which should also compose IO::Readable and IO::Writeable independent of the open mode).
So the idea is not about having the object to have the roles dinamically composed and de-composed depending on the access mode, but to have a way to implement a custom IO object that performs only the features it want to implement and yet being able to be used interchangeably with other IO objects.
That way, in the code that uses an IO object, if you want to be able to do unbuffered raw read from the object you receive as argument, you use
sub foo(IO::Readable $bar) {...}
and that way, it should be easy to provide a entirely made-up IO object that can be used by foo without any harm or magic.
daniel
|
| | 3 answer | Add comment |
Tuesday, 17 February 2009
|
| Issue with bind_param_inout and sys_refcursor Snutr 22:24:45 |
| | Hello,
I'm having an issue with getting a sys_refcursor back from a function.
Particulars: PERL version: 5.8.3 Oracle Client: 10.2.0.4 32 bit (using lib32) DBI version 1.41
The function returns a sys_refcursor.
$sth = $dbh->prepare(q{begin :csr := my_function('12345','',''); end;});
my $sth2; $sth->bind_param_inout(":csr", \$sth2, 0, { ora_type => ORA_RSET } );
$sth->execute();
$sth->finish; $dbh->disconnect;
It fails and produces the following output:
Field 9 has an Oracle type (108) which is not explicitly supported at ./test4_ora.pl line 23. Field 18 has an Oracle type (108) which is not explicitly supported at ./test4_ora.pl line 23. Field 19 has an Oracle type (108) which is not explicitly supported at ./test4_ora.pl line 23. Field 20 has an Oracle type (108) which is not explicitly supported at ./test4_ora.pl line 23. DBD::Oracle::st execute failed: ERROR OCIDefineObject call needed but not implemented yet [for Statement "declare csr sys_refcursor; begin :csr := my_function('12345','',''); end;" with ParamValues: :csr=DBI::st=HASH(0x33180c)] at ./test4_ora.pl line 23.
However I can execute the function if I don't use the bind_param_inout:
$sth = $dbh->prepare(q{declare csr sys_refcursor; begin csr := my_function('12345','',''); end;}); $sth->execute();
and it does not give me any errors.
I've tried:
$sth = $dbh->prepare(q{declare csr sys_refcursor; begin csr := my_function('12345','',''); csr2 := csr; end;});
my $sth2; $sth->bind_param_inout(":csr2", \$sth2, 0, { ora_type => ORA_RSET } );
and it gives me the same Oracle type (108) errors.
Is there an issue with the DBI version I'm using along with my Oracle client or am I not doing something right?
I appreciate your help.
Phil
|
| | 6 answers | Add comment |
|
| Detecting side-effects in Perl 6 (Was: Re: infectious traits and
pure functions) Daniel Ruoso 20:04:18 |
| | Em Seg, 2009-02-16 s 21:21 -0800, Darren Duncan escreveu:
marking it as consisting of just immutable values, and in the routines case marking it as having no side effects The problem is that you can't really know wether a value is immutable or not, we presume a literal 1 to be immutable, but even if you receive Int $i), it doesn't mean $i is immutable, because that signature only checks if $i ~~ Int, which actually results in $i.does(Int).
The twisted part is that $i.does(Int) is a regular method call on $i, which means that $i might be of whatever type, and be accepted by that signature by simply replying True on "does".
The only exception to that rule are the native types, which are guaranteed to always be of that actual type, you can't "lie" about a native int, as you can with Int.
Even then, you would have to check if all the multi-variants for the operators used in that function are free of side-effects as well, because no one stops you from writing:
multi infix:<+> (int where { 2 } $i, int where { 2 } $j) { say "The Big Brother is Watching You!" return 5; }
or worse
multi infix:<+> (int where { 2 } $i, int where { 2 } $j) { return OtherTypeThatHasSideEffectsButDoesInt.new initial_value(5)); }
So, while I agree that it would be very cool to make pure functions optimizeable somehow, you simply can't be sure about it.
OTOH, S06 already propose an optimization hint, which should do what you want, look for "is cached".
daniel
|
| | 7 answers | Add comment |
|
| Re: r25328 - docs/Perl6/Spec (fwd) Timothy S. Nelson 14:59:46 |
| | I didn't realise this hadn't gone to the list. Enjoy, all .
---------- Forwarded message ---------- Date: Tue, 17 Feb 2009 14:34:07 +1100 (EST) From: Timothy S. Nelson <wayland@wayland.id.au> To: Leon Timmermans <fawaka@gmail.com> Subject: Re: r25328 - docs/Perl6/Spec
On Mon, 16 Feb 2009, Leon Timmermans wrote:
On Mon, Feb 16, 2009 at 4:50 AM, Timothy S. Nelson <wayland@wayland.id.au> wrote: I like it if we can make it work, but it may be too nonsensical to get anything useful out of it. See my discussion below. So far, all ideas based on it result in incredibly verbose code. Creating an IO object should only be one statement. Anything else is failure IMNSHO. I see the problem; lets see if we can address that one too .
First, let me reprint an example I gave below:
$socket = new IO::Socket::INET($RemoteHost, $RemotePort, OtherOption => 1); $socket.Blockingness = 1; # Ok, maybe not blockingness, but you know what I $socket.OtherOption = 0; # Changed our mind from what we said in the class $socket.open(); # This could be called "connect", maybe I wasn't very clear here in what I was trying to demonstrate. This example needed more "..." in it. I was assuming that the lines were not all immediately following each other, but I in no way communicated that; sorry .
Allow me to point out that if I wanted to write the first three lines of what I proposed above in a single call, I'd do it like this:
$socket = new IO::Socket::INET($RemoteHost, $RemotePort, OtherOption => 0, Blockingness => 1, );
...which I hope you'll agree is vaguely perlish. Hopefully we can also choose sensible defaults for all these options.
My assumption was that people would sometimes want to create an IO object without opening/connecting it, which is why I separated the creation and .open() calls into two separate statements. But choosing sensible defaults applies here; what if we had it open by default on creation unless someone passes in a NoOpen => 1 option? Or maybe leave that to the implementations; files open by default, and sockets don't?
This was an example of me not thinking. Basically, it was because it was easier than writing IO::Readable IO::Writeable. I'll ignore the question as it crops up throughout; someone feel free to replace POSIX with Most of them should not be doing defined as implementing both. If a file is opened read-only, the object it returns should not be IO::Writeable. Hence, IO::File and such shouldn't be implementing IO::Readable or IO::Writeable. Such things should remain orthogonal, that is the whole idea of using roles! Ok, I'm vaguely starting to see the purpose of all this . Say I do this:
$fh = new IO::File($filename); while($_ = $fh.getline) { push @lines; } $fh.close();
Yes I know there are better ways to do it, but how does IO::Readable get there? Does it get mixed in at open time or something?
As a rakudo user, I'm also wondering whether we shouldn't be referring more to the Parrot IO stuff, but that may just be me. Parrot has very different goals for its IO interface: being able to implement the IO of all implemented languages is more important than having the best possible interface. In short, it's an implementation detail. Sorry, I wasn't clear again. I was thinking more from the point of view that a number of the things we've said appear to refer to the underlying OS calls and how they map to Perl6. I was thinking maybe we should talk about how the Parrot calls map to Perl6 (in our discussion, not in the Spec). But Maybe they're similar enough anyway that it doesn't really matter .
Question -- is there a reason this is in IO, instead of eg. S29? If AFAIK it's mostly used for obscure IO calls. I do agree it shouldn't really be in S16 though. Ok, I've moved it.
Disagree -- I think these belong in IO::Unbuffered. Maybe we could make that optional, though  . It may have a purpose in IO::POSIX, but other than that it doesn't make too much sense to me. The interface is stuck in 1969. We should make our open flexible enough that it can handle the use cases that now require sysopen, without having the same sucky interface. Sorry, I was unclear. I don't think those calls belong in IO::Unbuffered, but that whatever does our open should, if the object does IO::Unbuffered, apply the correct parameters. But I agree with you about unification of interface.
Hmm. I still haven't gotten the hang of Perl 6. What I want is for the name of this function to be the one that automatically gets called on object creation. Then you do something like this: $fobj = new IO::File($filename); # Creates handle $fobj.open(); # opens file Opening a file shouldn't be two lines, this is Perl! I think this whole Openable thing is harming us. Simple things should be simple. I agree about simplicity; see my comments at the top about opening/not opening by default.
Should it? I'm just thinking about the interactions between IO::File and IO::FileSystem. Maybe I'm just wondering about the name  . I'd argue I think I was out date, it's apparently called IO::FileSystem now (more OS neutral I guess). I think IO::Filesystem is more like a directory handle, and IO::FileSystemEntry is more like IO::Stattable, which means that I need to document IO::FileSystemEntry, and separate it from IO::FileSystem.
has IO::FileSystemEntry $FSEntry; ...and that you could then do: $fobj = new IO::File($filename); if($fobj.FSEntry.ModificationTime > '2008') { print "Modified this year\n"; ...and incidentally, the above is an example of why I wanted to separate the object creation and the open calls. But with my comments at the top of this e-mail, this would still be possible, but the "simple things simple" rule would also be conserved.
In other words, I'm arguing that maybe we need a separate class for the calls that do stuff to the "outside" of a file, verses the calls that do stuff to the "inside" of a file. But maybe that's what roles are for. I'm undecided. Thoughts, anyone? Yeah, it should be a separate class, definitely. Has-a, not is-a. Great .
I'd break this into two; one like the init call above that creates the object, and has the local and remote host/port passed in, but doesn't do Maybe something like this example for a client: $socket = new IO::Socket::INET($RemoteHost, $RemotePort, OtherOption => 1); $socket.Blockingness = 1; # Ok, maybe not blockingness, but you know what I $socket.OtherOption = 0; # Changed our mind from what we said in the class $socket.open(); # This could be called "connect", maybe That's simply not Perlish. There is no excuse why it shouldn't be possible to open a socket in one line. This would be a setback compared to Perl 5's IO::Socket::INET. Let's not make Perl 6 a new Java. Simple things should be simple. Agreed. I discussed this at the top of this e-mail, instead of here.
I'm kinda keen to call the function open() instead of connect(), so that things are more consistent across the whole IO interface, but I agree that attaching the listen stuff to that call was a bad idea. Why would different things need to have the same name? That makes absolutely no sense at all. I guess I don't see them as being different in any way. In both cases, you specify the data source that you want to connect to, and get a handle to act on it.
For the server, I'd suggest an additional role, IO::Listening, that has both listen() and accept() calls on it. Would that work for you? Or is that essentially exactly what you suggested below, but with a name change?  What I suggested is something that combines bind() and listen() on creation. Ok, sounds good, although I'd like the option to turn them both off if useful.
HTH, and hopefully I've communicated marginally better this time.
--------------------------------------------------------------------- | Name: Tim Nelson | Because the Creator is, | | E-mail: wayland@wayland.id.au | I am | ---------------------------------------------------------------------
----BEGIN GEEK CODE BLOCK---- Version 3.12 GCS d+++ s+: a- C++$ U+++$ P+++$ L+++ E- W+ N+ w--- V- PE(+) Y+>++ PGP->+++ R(+) !tv b++ DI++++ D G+ e++>++++ h! y- -----END GEEK CODE BLOCK-----
--------------------------------------------------------------------- | Name: Tim Nelson | Because the Creator is, | | E-mail: wayland@wayland.id.au | I am | ---------------------------------------------------------------------
----BEGIN GEEK CODE BLOCK---- Version 3.12 GCS d+++ s+: a- C++$ U+++$ P+++$ L+++ E- W+ N+ w--- V- PE(+) Y+>++ PGP->+++ R(+) !tv b++ DI++++ D G+ e++>++++ h! y- -----END GEEK CODE BLOCK-----
|
| | Add comment |
|
| r25367 - docs/Perl6/Spec Guest 14:26:51 |
| | Author: wayland Date: 2009-02-17 12:26:51 +0100 (Tue, 17 Feb 2009) New Revision: 25367
Modified: docs/Perl6/Spec/S16-io.pod Log: S16: Made some improvements based on http://www.mail-archive.com/perl6-language@perl.org/msg28566.html
(Thanks to Mark Overmeer for the link)
Modified: docs/Perl6/Spec/S16-io.pod =================================================================== --- docs/Perl6/Spec/S16-io.pod 2009-02-17 10:55:14 UTC (rev 25366) +++ docs/Perl6/Spec/S16-io.pod 2009-02-17 11:26:51 UTC (rev 25367) @@ -68,6 +68,11 @@ you're going to need to encode it later, or use "getc" or other IO::Readable::Encoded methods. +=item method Bool is_readable() + +Indicates whether socket is actually opened for reading. Closed sockets +return false. + =back =head2 IO::Writeable @@ -87,6 +92,11 @@ encoded data, you should decode it first, or use "print" or other IO::Writeable::Encoded methods. +=item method Bool is_writeable() + +Indicates whether socket is actually opened for writing. Closed sockets +return false. + =back =head2 IO::Seekable @@ -411,7 +421,7 @@ =item init - method init(String $filename, $options?); + method init(Str $filename, $options?); method init(Int $fd); # Read @@ -439,7 +449,11 @@ This reads directories, deletes filesystem entries, creates links, and the like. class IO::FileSystem does IO::Streamable { - has IO::FileSystemEntry $cwd; + has IO::FileSystemEntry $.cwd; # Current working directory + has IO::FileSystemEntry $.basepath; # The Unix mount point, or Windows drive letter, or whatever + has Str $.type; # ext3, ntfs, vfat, reiserfs, etc + has Str $.illegal_chars; # ie. /\x0 + has Int $.max_path; ... } @@ -447,6 +461,12 @@ =item glob +Returns FileSystemEntry objects + +=item find + +Returns FileSystemEntry objects + =item link =item lstat @@ -501,6 +521,8 @@ =head2 IO::FilesystemEntry class IO::FileSystemEntry { + has Str $path; + has IO::FileSystemEntryACL @.acls; ... } @@ -662,8 +684,68 @@ the stat fails, all subsequent tests on the stat buffer also evaluate to false. +=item realpath + + method Str realpath(); + +Gets the real path to the object, resolving softlinks/shortcuts, etc + +=item parent + + method IO::FileSystemEntry parent(); + +=item isSameFile + + method isSameFile(Str $filename); + +Test whether the specified filename is the same file as this file. On a Unix system, +this would presumably be done by comparing inode numbers or something. + =back +=head2 IO::FileSystemEntryACL + +This is a basic abstraction; for better control, use the operating-system specific +interfaces [not designed yet], over which this is a thin veneer. + +class IO::FileSystemEntryACL { + has Str $.type; # "User", "Group", "Everyone", ??? + has Str $.id; # username or groupname; unused for $type eq "Everyone" + has %.permissions; + # Unsupported values may (or may not) throw + # UnsupportedPermission when set or read + has IO::FileSystemEntry $.owningObject; +... +} + +The permissions used in %permissions are: + +=over + +=item Readable + +Should be supported by all filesystems as an item to read from the hash for the group +"Everyone". + +=item Writeable + +Should be supported by all filesystems as an item to read from the hash for the group +"Everyone". + +=item Executeable + +Supported on most Unix systems, anyway + +=item Default + +An ACL of User,fred,Default sets the user "fred" to be the owner of the file. This can be +done with groups too. Work on Unix, at least. + +=back + +The $.owningObject attribute of FileSystemEntryACL shows what the ACL is set on. On a +Windows system, this can be a parent directory, as permissions are inherited. + =head2 IO::Socket::TCP class IO::Socket::TCP does IO::Socket does IO::Streamable {
|
| | Add comment |
|
| r25364 - docs/Perl6/Spec Guest 13:06:57 |
| | Author: wayland Date: 2009-02-17 11:06:57 +0100 (Tue, 17 Feb 2009) New Revision: 25364
Modified: docs/Perl6/Spec/S16-io.pod Log: S16: Added cwd to FileSystem
Modified: docs/Perl6/Spec/S16-io.pod =================================================================== --- docs/Perl6/Spec/S16-io.pod 2009-02-17 08:38:53 UTC (rev 25363) +++ docs/Perl6/Spec/S16-io.pod 2009-02-17 10:06:57 UTC (rev 25364) @@ -439,6 +439,7 @@ This reads directories, deletes filesystem entries, creates links, and the like. class IO::FileSystem does IO::Streamable { + has IO::FileSystemEntry $cwd; ... } @@ -499,7 +500,7 @@ =head2 IO::FilesystemEntry -class IO::FileSystem { +class IO::FileSystemEntry { ... }
|
| | Add comment |
|
|