Subject: | Function open must be tested |
Good morning,
i send you patch which has use testing in every open file. There must be
error checking, because file can't be opened or created.
With sincerelly Igor Bujna
Subject: | Sass.diff |
--- lib/Dancer/Plugin/Preprocess/Sass.pm~ 2011-09-19 22:53:19.000000000 +0200
+++ lib/Dancer/Plugin/Preprocess/Sass.pm 2012-04-20 02:07:46.100770021 +0200
@@ -15,7 +15,7 @@
=cut
-our $VERSION = '0.01';
+our $VERSION = '0.02';
my $settings = plugin_setting;
@@ -59,15 +59,18 @@
return undef;
}
- open (my $f, '<', $sass_file);
- my $contents;
- {
- local $/;
- $contents = <$f>;
- }
- close($f);
-
- return $sass->$method($contents);
+ my $f;
+ if (!open ($f, '<', $sass_file)) {
+ warning __PACKAGE__ . ": Can't open for writing " . $sass_file . " : $!";
+ return undef;
+ }
+ my $contents;
+ {
+ local $/;
+ $contents = <$f>;
+ }
+ close($f);
+ return $sass->$method($contents);
}
hook before_file_render => sub {
@@ -96,9 +99,13 @@
if (defined $css) {
# Save the generated CSS data
- open(my $f, '>', $path);
- print {$f} $css;
- close($f);
+ my $f;
+ if (!open($f, '>', $path)) {
+ warning __PACKAGE__ . ": Can't open for writing " . $path . " : $!";
+ } else {
+ print {$f} $css;
+ close($f);
+ }
}
}
}
@@ -125,9 +132,13 @@
if ($settings->{save}) {
# Saving enabled -- save the generated CSS as the requested file
- open(my $f, '>', $css_file_abs);
- print {$f} $css;
- close($f);
+ my $f;
+ if (!open($f, '>', $css_file_abs)) {
+ warning __PACKAGE__ . ": Can't open for writing " . $css_file_abs . " : $!";
+ } else {
+ print {$f} $css;
+ close($f);
+ }
}
header 'content-type' => 'text/css';