From: Tony Cook <tony@develop=help.com> Date: Fri, 11 Mar 2005 11:57:34 +0000 (+0000) Subject: - the convert, crop, rotate, copy, matrix_transform, to_paletted, to_rgb8, X-Git-Tag: Imager-0.48^2~202 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/34b3f7e677dad923311b69d88e176e09686957ff - 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 --- diff --git a/Changes b/Changes index a394873a..895c26c1 100644 --- 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 ================================================================= diff --git a/Imager.pm b/Imager.pm index cf8e6351..f5c965de 100644 --- 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})) { diff --git a/t/t01introvert.t b/t/t01introvert.t index 9813fa71..e6dce3b6 100644 --- a/t/t01introvert.t +++ b/t/t01introvert.t @@ -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); diff --git a/t/t023palette.t b/t/t023palette.t index 8110619c..65e38c9a 100644 --- a/t/t023palette.t +++ b/t/t023palette.t @@ -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) = @_; diff --git a/t/t40scale.t b/t/t40scale.t index 79a8e783..8ef22e65 100644 --- a/t/t40scale.t +++ b/t/t40scale.t @@ -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 diff --git a/t/t64copyflip.t b/t/t64copyflip.t index aa9d7483..69d3a51b 100644 --- a/t/t64copyflip.t +++ b/t/t64copyflip.t @@ -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"); +} + diff --git a/t/t65crop.t b/t/t65crop.t index ad95b649..03096c7e 100644 --- a/t/t65crop.t +++ b/t/t65crop.t @@ -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"); +} diff --git a/t/t67convert.t b/t/t67convert.t index be5272f2..466f676f 100644 --- a/t/t67convert.t +++ b/t/t67convert.t @@ -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"); +}