Perlito5/JavaScript3/IO.pm untested

filter: Statementstmt 0.0% 0 / 4 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 2 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 7 CC 1 SCAR 6.9
CC
1
Cov
0%
emit_javascript3
2.0
BEGIN
2.0
CRAP 2.0
1 use v5;
2  
3 package Perlito5::JavaScript3::IO;
4  
5 sub emit_javascript3 {
6  
7 return <<'EOT';
8 //
9 //
10 // lib/Perlito5/JavaScript3/IO.js
11 //
12 // I/O functions for "Perlito" Perl5-in-JavaScript3
13 //
14 // AUTHORS
15 //
16 // Flavio Soibelmann Glock fglock@gmail.com
17 //
18 // COPYRIGHT
19 //
20 // Copyright 2009, 2010, 2011, 2012 by Flavio Soibelmann Glock and others.
21 //
22 // This program is free software; you can redistribute it and/or modify it
23 // under the same terms as Perl itself.
24 //
25 // See http://www.perl.com/perl/misc/Artistic.html
26  
27 var isNode = typeof require != "undefined";
28 if (isNode) {
29  
30 var fs = require("fs");
31  
32 p5atime = function(s) {
33 s = p5str(s);
34 try {
35 var stat = fs.statSync(s); return stat["atime"];
36 }
37 catch(err) {
38 return '';
39 }
40 };
41 p5mtime = function(s) {
42 s = p5str(s);
43 try {
44 var stat = fs.statSync(s); return stat["mtime"];
45 }
46 catch(err) {
47 return '';
48 }
49 };
50 p5ctime = function(s) {
51 s = p5str(s);
52 try {
53 var stat = fs.statSync(s); return stat["ctime"];
54 }
55 catch(err) {
56 return '';
57 }
58 };
59 p5size = function(s) {
60 s = p5str(s);
61 try {
62 var stat = fs.statSync(s); return stat["size"];
63 }
64 catch(err) {
65 return '';
66 }
67 };
68 p5is_file = function(s) {
69 s = p5str(s);
70 try {
71 var stat = fs.statSync(s); return stat.isFile() ? 1 : 0;
72 }
73 catch(err) {
74 return '';
75 }
76 };
77 p5is_directory = function(s) {
78 s = p5str(s);
79 try {
80 var stat = fs.statSync(s); return stat.isDirectory() ? 1 : 0;
81 }
82 catch(err) {
83 return '';
84 }
85 };
86 p5file_exists = function(s) {
87 s = p5str(s);
88 return p5is_file(s) || p5is_directory(s);
89 };
90  
91 CORE.chdir = function(List__) {
92 try {
93 process.chdir(p5str(List__[0]));
94 return 1;
95 }
96 catch(err) {
97 return '';
98 }
99 };
100  
101 CORE.close = function(List__) {
102 try {
103 fs.closeSync(p5str(List__[0]));
104 return 1;
105 }
106 catch(err) {
107 p5pkg["main"]["v_!"] = err;
108 return '';
109 }
110 };
111  
112 CORE.exit = function(List__) {
113 process.exit(List__[0]);
114 };
115  
116 CORE.rename = function(List__) {
117 try {
118 fs.renameSync(p5str(List__[0]), p5str(List__[1]));
119 return 1;
120 }
121 catch(err) {
122 p5pkg["main"]["v_!"] = err;
123 return '';
124 }
125 };
126  
127 CORE.unlink = function(List__) {
128 var count = 0;
129 try {
130 for(var i = 0; i < List__.length; i++) {
131 fs.unlinkSync(p5str(List__[i]));
132 count++;
133 }
134 return count;
135 }
136 catch(err) {
137 p5pkg["main"]["v_!"] = err;
138 return count;
139 }
140 };
141  
142 }
143  
144 EOT
145 } # end of emit_javascript3()
146  
147 1;
148