]> git.imager.perl.org - imager.git/commitdiff
- the convert, crop, rotate, copy, matrix_transform, to_paletted, to_rgb8,
authorTony Cook <tony@develop=help.com>
Fri, 11 Mar 2005 11:57:34 +0000 (11:57 +0000)
committerTony Cook <tony@develop=help.com>
Fri, 11 Mar 2005 11:57:34 +0000 (11:57 +0000)
  scaleX and scaleY methods now warn when called in void context.
  http://rt.cpan.org/NoAuth/Bug.html?id=9672

Changes
Imager.pm
t/t01introvert.t
t/t023palette.t
t/t40scale.t
t/t64copyflip.t
t/t65crop.t
t/t67convert.t

diff --git a/Changes b/Changes
index a394873af49d0bf99207ac9e24433a2ebf63e848..895c26c15a18271bea7fcdb5f388db978a2d946c 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1031,6 +1031,9 @@ Revision history for Perl extension Imager.
 - some test scripts have been modified to use Test::More, which is now
   included under the t directory.  Eventually all will be modified to use
   Test::More and the duplicates in t/testtools.pl will be removed
+- the convert, crop, rotate, copy, matrix_transform, to_paletted, to_rgb8, 
+  scaleX and scaleY methods now warn when called in void context.
+  http://rt.cpan.org/NoAuth/Bug.html?id=9672
 
 =================================================================
 
index cf8e6351b6a413f13bbf9c7ee09c3bae03000300..f5c965de07b898dcac2f442f1cb045cf81f8ba4e 100644 (file)
--- a/Imager.pm
+++ b/Imager.pm
@@ -550,6 +550,12 @@ sub copy {
   my $self = shift;
   unless ($self->{IMG}) { $self->{ERRSTR}='empty input image'; return undef; }
 
+  unless (defined wantarray) {
+    my @caller = caller;
+    warn "copy() called in void context - copy() returns the copied image at $caller[1] line $caller[2]\n";
+    return;
+  }
+
   my $newcopy=Imager->new();
   $newcopy->{IMG}=i_img_new();
   i_copy($newcopy->{IMG},$self->{IMG});
@@ -581,8 +587,13 @@ sub paste {
 sub crop {
   my $self=shift;
   unless ($self->{IMG}) { $self->{ERRSTR}='empty input image'; return undef; }
-
   
+  unless (defined wantarray) {
+    my @caller = caller;
+    warn "crop() called in void context - crop() returns the cropped image at $caller[1] line $caller[2]\n";
+    return;
+  }
+
   my %hsh=@_;
 
   my ($w, $h, $l, $r, $b, $t) =
@@ -753,6 +764,12 @@ sub to_paletted {
     $opts = shift;
   }
 
+  unless (defined wantarray) {
+    my @caller = caller;
+    warn "to_paletted() called in void context - to_paletted() returns the converted image at $caller[1] line $caller[2]\n";
+    return;
+  }
+
   my $result = Imager->new;
   $result->{IMG} = i_img_to_pal($self->{IMG}, $opts);
 
@@ -772,6 +789,12 @@ sub to_rgb8 {
   my $self = shift;
   my $result;
 
+  unless (defined wantarray) {
+    my @caller = caller;
+    warn "to_rgb8() called in void context - to_rgb8() returns the cropped image at $caller[1] line $caller[2]\n";
+    return;
+  }
+
   if ($self->{IMG}) {
     $result = Imager->new;
     $result->{IMG} = i_img_to_rgb($self->{IMG})
@@ -1644,6 +1667,12 @@ sub scaleX {
   my $self=shift;
   my %opts=(scalefactor=>0.5,@_);
 
+  unless (defined wantarray) {
+    my @caller = caller;
+    warn "scaleX() called in void context - scaleX() returns the scaled image at $caller[1] line $caller[2]\n";
+    return;
+  }
+
   unless ($self->{IMG}) { $self->{ERRSTR}='empty input image'; return undef; }
 
   my $img = Imager->new();
@@ -1663,6 +1692,12 @@ sub scaleY {
   my $self=shift;
   my %opts=(scalefactor=>0.5,@_);
 
+  unless (defined wantarray) {
+    my @caller = caller;
+    warn "scaleY() called in void context - scaleY() returns the scaled image at $caller[1] line $caller[2]\n";
+    return;
+  }
+
   unless ($self->{IMG}) { $self->{ERRSTR}='empty input image'; return undef; }
 
   my $img = Imager->new();
@@ -1868,6 +1903,13 @@ sub flip {
 sub rotate {
   my $self = shift;
   my %opts = @_;
+
+  unless (defined wantarray) {
+    my @caller = caller;
+    warn "rotate() called in void context - rotate() returns the rotated image at $caller[1] line $caller[2]\n";
+    return;
+  }
+
   if (defined $opts{right}) {
     my $degrees = $opts{right};
     if ($degrees < 0) {
@@ -1920,6 +1962,12 @@ sub matrix_transform {
   my $self = shift;
   my %opts = @_;
 
+  unless (defined wantarray) {
+    my @caller = caller;
+    warn "copy() called in void context - copy() returns the copied image at $caller[1] line $caller[2]\n";
+    return;
+  }
+
   if ($opts{matrix}) {
     my $xsize = $opts{xsize} || $self->getwidth;
     my $ysize = $opts{ysize} || $self->getheight;
@@ -2334,6 +2382,12 @@ sub convert {
   my ($self, %opts) = @_;
   my $matrix;
 
+  unless (defined wantarray) {
+    my @caller = caller;
+    warn "convert() called in void context - convert() returns the converted image at $caller[1] line $caller[2]\n";
+    return;
+  }
+
   # the user can either specify a matrix or preset
   # the matrix overrides the preset
   if (!exists($opts{matrix})) {
index 9813fa71a68c4751af4b25f41c4e0b74591fb025..e6dce3b69ad670cb51dac17942c44fb6bd8f47f2 100644 (file)
@@ -4,7 +4,7 @@
 
 use strict;
 use lib 't';
-use Test::More tests=>93;
+use Test::More tests=>95;
 
 BEGIN { use_ok(Imager => qw(:handy :all)) }
 
@@ -228,6 +228,22 @@ cmp_ok(Imager->errstr, '=~', qr/channels must be between 1 and 4/,
   }
 }
 
+{ # http://rt.cpan.org/NoAuth/Bug.html?id=9672
+  my $warning;
+  local $SIG{__WARN__} = 
+    sub { 
+      $warning = "@_";
+      my $printed = $warning;
+      $printed =~ s/\n$//;
+      $printed =~ s/\n/\n\#/g; 
+      print "# ",$printed, "\n";
+    };
+  my $img = Imager->new(xsize=>10, ysize=>10);
+  $img->to_rgb8(); # doesn't really matter what the source is
+  cmp_ok($warning, '=~', 'void', "correct warning");
+  cmp_ok($warning, '=~', 't01introvert\\.t', "correct file");
+}
+
 sub check_add {
   my ($im, $color, $expected) = @_;
   my $index = Imager::i_addcolors($im, $color);
index 8110619c44aaa628884900e5a90688ef433d6174..65e38c9aab604f348c411a2a08a129c8aea00b8e 100644 (file)
@@ -2,7 +2,7 @@
 # some of this is tested in t01introvert.t too
 use strict;
 use lib 't';
-use Test::More tests => 57;
+use Test::More tests => 59;
 BEGIN { use_ok("Imager"); }
 
 my $img = Imager->new(xsize=>50, ysize=>50, type=>'paletted');
@@ -174,6 +174,22 @@ cmp_ok(Imager->errstr, '=~', qr/Channels must be positive and <= 4/,
   }
 }
 
+{ # http://rt.cpan.org/NoAuth/Bug.html?id=9672
+  my $warning;
+  local $SIG{__WARN__} = 
+    sub { 
+      $warning = "@_";
+      my $printed = $warning;
+      $printed =~ s/\n$//;
+      $printed =~ s/\n/\n\#/g; 
+      print "# ",$printed, "\n";
+    };
+  my $img = Imager->new(xsize=>10, ysize=>10);
+  $img->to_paletted();
+  cmp_ok($warning, '=~', 'void', "correct warning");
+  cmp_ok($warning, '=~', 't023palette\\.t', "correct file");
+}
+
 sub coloreq {
   my ($left, $right, $comment) = @_;
 
index 79a8e783bdaceebc09e0403482b5c5829eaa4ea5..8ef22e65b705df7b71d0427101a1676cceb7bcc3 100644 (file)
@@ -1,7 +1,7 @@
 #!perl -w
 use strict;
 use lib 't';
-use Test::More tests => 12;
+use Test::More tests => 16;
 
 BEGIN { use_ok(Imager=>':all') }
 
@@ -40,6 +40,14 @@ ok($scaleimg->write(file=>'testout/t40scale2.ppm',type=>'pnm'),
   $img->scale(scalefactor=>0.25);
   cmp_ok($warning, '=~', qr/void/, "check warning");
   cmp_ok($warning, '=~', qr/t40scale\.t/, "check filename");
+  $warning = '';
+  $img->scaleX(scalefactor=>0.25);
+  cmp_ok($warning, '=~', qr/void/, "check warning");
+  cmp_ok($warning, '=~', qr/t40scale\.t/, "check filename");
+  $warning = '';
+  $img->scaleY(scalefactor=>0.25);
+  cmp_ok($warning, '=~', qr/void/, "check warning");
+  cmp_ok($warning, '=~', qr/t40scale\.t/, "check filename");
 }
 { # https://rt.cpan.org/Ticket/Display.html?id=7467
   # segfault in Imager 0.43
index aa9d7483f002408cb76c87f3450fc9430bbdc4d3..69d3a51bd96a1b0613b46f424f901c4015876cb8 100644 (file)
@@ -1,7 +1,7 @@
 #!perl -w
 use strict;
 use lib 't';
-use Test::More tests=>51;
+use Test::More tests=>57;
 use Imager;
 
 #$Imager::DEBUG=1;
@@ -113,3 +113,27 @@ sub rot_test {
   }
 }
 
+{ # http://rt.cpan.org/NoAuth/Bug.html?id=9672
+  my $warning;
+  local $SIG{__WARN__} = 
+    sub { 
+      $warning = "@_";
+      my $printed = $warning;
+      $printed =~ s/\n$//;
+      $printed =~ s/\n/\n\#/g; 
+      print "# ",$printed, "\n";
+    };
+  my $img = Imager->new(xsize=>10, ysize=>10);
+  $img->copy();
+  cmp_ok($warning, '=~', 'void', "correct warning");
+  cmp_ok($warning, '=~', 't64copyflip\\.t', "correct file");
+  $warning = '';
+  $img->rotate(degrees=>5);
+  cmp_ok($warning, '=~', 'void', "correct warning");
+  cmp_ok($warning, '=~', 't64copyflip\\.t', "correct file");
+  $warning = '';
+  $img->matrix_transform(matrix=>[1, 1, 1]);
+  cmp_ok($warning, '=~', 'void', "correct warning");
+  cmp_ok($warning, '=~', 't64copyflip\\.t', "correct file");
+}
+
index ad95b64933fd4e9758c1f3280f6ef6c2482c395f..03096c7ea407d7a965252bfaf3af263f07aacc65 100644 (file)
@@ -1,7 +1,7 @@
 #!perl -w
 use strict;
 use lib 't';
-use Test::More tests => 58;
+use Test::More tests => 60;
 require "t/testtools.pl";
 use Imager;
 
@@ -156,3 +156,18 @@ SKIP:
         "and message");
 }
 
+{ # http://rt.cpan.org/NoAuth/Bug.html?id=9672
+  my $warning;
+  local $SIG{__WARN__} = 
+    sub { 
+      $warning = "@_";
+      my $printed = $warning;
+      $printed =~ s/\n$//;
+      $printed =~ s/\n/\n\#/g; 
+      print "# ",$printed, "\n";
+    };
+  my $img = Imager->new(xsize=>10, ysize=>10);
+  $img->crop(left=>5);
+  cmp_ok($warning, '=~', 'void', "correct warning");
+  cmp_ok($warning, '=~', 't65crop\\.t', "correct file");
+}
index be5272f240e55e2061d3a59821f043b09bbe4f87..466f676f1a9515b8752971f85138117cef3aa7f9 100644 (file)
@@ -2,7 +2,7 @@
 use strict;
 use Imager qw(:all :handy);
 use lib 't';
-use Test::More tests=>17;
+use Test::More tests=>19;
 
 Imager::init("log"=>'testout/t67convert.log');
 
@@ -93,3 +93,18 @@ SKIP:
      "colour is as expected");
 }
 
+{ # http://rt.cpan.org/NoAuth/Bug.html?id=9672
+  my $warning;
+  local $SIG{__WARN__} = 
+    sub { 
+      $warning = "@_";
+      my $printed = $warning;
+      $printed =~ s/\n$//;
+      $printed =~ s/\n/\n\#/g; 
+      print "# ",$printed, "\n";
+    };
+  my $img = Imager->new(xsize=>10, ysize=>10);
+  $img->convert(preset=>"grey");
+  cmp_ok($warning, '=~', 'void', "correct warning");
+  cmp_ok($warning, '=~', 't67convert\\.t', "correct file");
+}