From 3550abf6ec1f08c5e280cb12966002bb3108c34e Mon Sep 17 00:00:00 2001 From: tokuhirom Date: Tue, 8 May 2012 08:00:34 +0900 Subject: [PATCH] added stat() function --- TODO.mkdn | 2 ++ lib/Nana/Translator/Perl/Builtins.pm | 48 +++++++++++++++++++++++++++- t/tra/builtins/stat.tra | 11 +++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 t/tra/builtins/stat.tra diff --git a/TODO.mkdn b/TODO.mkdn index f79d8d6..720e5da 100644 --- a/TODO.mkdn +++ b/TODO.mkdn @@ -8,6 +8,8 @@ TODO list * ENV * TSGI? * split Tlack related things to another package + * DBI integration + * template engine(T::MT?) BUGS ---- diff --git a/lib/Nana/Translator/Perl/Builtins.pm b/lib/Nana/Translator/Perl/Builtins.pm index 7370eb2..cc0315f 100644 --- a/lib/Nana/Translator/Perl/Builtins.pm +++ b/lib/Nana/Translator/Perl/Builtins.pm @@ -140,7 +140,9 @@ our %TORA_BUILTIN_FUNCTIONS = ( printf(@_); }, 'stat' => sub { - return File::stat::stat(@_); + $TORA_BUILTIN_CLASSES{'File::Stat'}->get_method( + 'new' + )->(@_); }, 'eval' => sub { my $src = shift; @@ -565,6 +567,50 @@ my %built_class_src = ( }, Int => +{ }, + 'File::Stat' => do { + my %h = ( + new => sub { + $TORA_BUILTIN_CLASSES{'File::Stat'}->create_instance( + [stat(@_)] + ) + }, + ); + + # 0 dev device number of filesystem + # 1 ino inode number + # 2 mode file mode (type and permissions) + # 3 nlink number of (hard) links to the file + # 4 uid numeric user ID of file's owner + # 5 gid numeric group ID of file's owner + # 6 rdev the device identifier (special files only) + # 7 size total size of file, in bytes + # 8 atime last access time in seconds since the epoch + # 9 mtime last modify time in seconds since the epoch + # 10 ctime inode change time in seconds since the epoch (*) + # 11 blksize preferred block size for file system I/O + # 12 blocks actual number of blocks allocated + my @params = qw( + 0 dev + 1 ino + 2 mode + 3 nlink + 4 uid + 5 gid + 6 rdev + 7 size + 8 atime + 9 mtime + 10 ctime + 11 blksiz + 12 blocks + ); + while (my ($no, $method) = splice @params, 0, 2) { + $h{$method} = sub { + self->data->[$no] + }; + } + \%h; + }, ); while (my ($class_name, $methods) = each %built_class_src) { $TORA_BUILTIN_CLASSES{$class_name} = do { diff --git a/t/tra/builtins/stat.tra b/t/tra/builtins/stat.tra new file mode 100644 index 0000000..185dcef --- /dev/null +++ b/t/tra/builtins/stat.tra @@ -0,0 +1,11 @@ +use Test::More *; + +my $stat = stat('t/dat/filetest/foo'); +is(typeof($stat), 'File::Stat'); +note($stat.uid()); +note($stat.gid()); +note($stat.mode()); +note($stat.atime()); +note($stat.ctime()); +note($stat.mtime()); +note($stat.ino());