Skip Menu |

This queue is for tickets about the OpenFrame CPAN distribution.

Report information
The Basics
Id: 2476
Status: open
Priority: 0/
Queue: OpenFrame

People
Owner: Nobody in particular
Requestors: spurkis [...] quiup.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 3.03
Fixed in: (no value)



Subject: [PATCH] $obj->new fails
The following fails in OpenFrame 3.03: my $obj1 = OpenFrame::Object->new(); my $obj2 = $obj1->new(); The attached patch fixes this, and introduces the $obj->class() method (which I like, but you might not :-). -Steve
diff -ruN OpenFrame-3.03.orig/lib/OpenFrame/Object.pm OpenFrame-3.03/lib/OpenFrame/Object.pm --- OpenFrame-3.03.orig/lib/OpenFrame/Object.pm Wed Mar 5 10:46:04 2003 +++ OpenFrame-3.03/lib/OpenFrame/Object.pm Fri May 2 08:56:54 2003 @@ -5,10 +5,10 @@ use OpenFrame; -our $VERSION="3.03"; +our $VERSION="3.031"; sub new { - my $class = shift; + my $class = shift->class; my $self = {}; bless $self, $class; $self->init(@_); @@ -25,9 +25,15 @@ my $pack = ref( $self ); my ($package, $filename, $line, $subroutine, $hasargs, $wantarray, $evaltext, $is_require, $hints, $bitmask) = caller( 1 ); + $subroutine =~ s/.*:://; if ($OpenFrame::DEBUG{ ALL } || $OpenFrame::DEBUG{ $pack }) { warnings::warn("[$pack\::$subroutine] $mesg"); } +} + +sub class { + my $thing = shift; + return ref($thing) || $thing; } 1; diff -ruN OpenFrame-3.03.orig/t/00object.t OpenFrame-3.03/t/00object.t --- OpenFrame-3.03.orig/t/00object.t Tue Aug 13 17:55:37 2002 +++ OpenFrame-3.03/t/00object.t Fri May 2 08:56:40 2003 @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::Simple tests => 3; +use Test::Simple tests => 4; use OpenFrame::Object; ok(1, "loaded"); @@ -15,5 +15,7 @@ }; ok($@, "error message thrown"); - +my $new_obj; +eval { $new_obj = $object->new; }; +ok($new_obj, 'new object from object');
I'm actually loathed to apply this patch. Unless of course a compelling reason why this should _ever_ be done can be provided. I really don't like constructors that can construct from an instance. I could understand the logic behind a constructor that could clone existing state to re- instantiate, but even then I would recommend a separate clone() method to perform those duties. I could however, be persuaded with arguments along the lines of creating a new method called new_from_instance() or new_with_instance(); Regards, James.