CC: | Slaven Rezic <slaven [...] rezic.de> |
Subject: | [PATCH] support for static const char |
Date: | Mon, 2 Nov 2009 23:27:56 +0100 |
To: | bug-Image-Xpm [...] rt.cpan.org |
From: | Slaven Rezic <slaven [...] rezic.de> |
---
MANIFEST | 1 +
Xpm.pm | 4 ++--
t/const.t | 44 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 47 insertions(+), 2 deletions(-)
create mode 100755 t/const.t
diff --git a/MANIFEST b/MANIFEST
index 7c6d4c1..8a80645 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,4 +1,5 @@
Xpm.pm
+t/const.t
t/xpm.t
MANIFEST
Makefile.PL
diff --git a/Xpm.pm b/Xpm.pm
index c639db3..8021e8b 100644
--- a/Xpm.pm
+++ b/Xpm.pm
@@ -5,7 +5,7 @@ package Image::Xpm; # Documented at the __END__
use strict;
use vars qw($VERSION @ISA);
-$VERSION = '1.09';
+$VERSION = '1.10';
use Image::Base;
@@ -381,7 +381,7 @@ sub load { # Object method
# Name of C string
if ($state == $STATE_ARRAY) {
croak "$err does not have a proper C array name"
- unless /static\s+char\s+\*\s*\w+\[\s*\]\s*=\s*\{/o; #}
+ unless /static\s+(?:const\s+)?char\s+\*\s*\w+\[\s*\]\s*=\s*\{/o; #}
$state = $STATE_VALUES;
next LINE;
}
diff --git a/t/const.t b/t/const.t
new file mode 100755
index 0000000..793ca43
--- /dev/null
+++ b/t/const.t
@@ -0,0 +1,44 @@
+use strict;
+
+BEGIN {
+ if (!eval q{
+ use Test::More;
+ 1;
+ }) {
+ print "1..0 # skip no Test::More module\n";
+ exit;
+ }
+}
+
+plan tests => 2;
+
+use Image::Xpm;
+
+my $TestImage = <<'EOT';
+/* XPM */
+static const char *noname[] = {
+/* width height ncolors chars_per_pixel */
+"4 10 4 1",
+/* colors */
+"` c #000000",
+"a c #FA1340",
+"b c #3BFA34",
+"c c #FFFF00",
+/* pixels */
+"````",
+"`aa`",
+"`aa`",
+"````",
+"`cc`",
+"`cc`",
+"````",
+"`bb`",
+"`bb`",
+"````"
+};
+EOT
+
+my $xpm = Image::Xpm->new(-width => 0, -height => 0);
+$xpm->load(\$TestImage);
+is($xpm->get('-width'), 4, 'Image with static const char loaded');
+is($xpm->get('-height'), 10);
--
1.6.1