Skip to content

Commit

Permalink
added stat() function
Browse files Browse the repository at this point in the history
  • Loading branch information
tokuhirom committed May 7, 2012
1 parent a23e818 commit 3550abf
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
2 changes: 2 additions & 0 deletions TODO.mkdn
Expand Up @@ -8,6 +8,8 @@ TODO list
* ENV
* TSGI?
* split Tlack related things to another package
* DBI integration
* template engine(T::MT?)

BUGS
----
Expand Down
48 changes: 47 additions & 1 deletion lib/Nana/Translator/Perl/Builtins.pm
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions 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());

0 comments on commit 3550abf

Please sign in to comment.