Given a class Foo, with Instance methods doSomething and new, this
fragment of a Class method has to be written just so to avoid load
and/or run time complaints:
if (ref($myfoo) && (ref($myfoo) eq 'Foo'))
{$myfoo = $myfoo->doSomething ( 'data' => $data );
}
else
{$myfoo = new Foo
('data' => $data, 'filename' => $filename);
}
1) If I don't test the ref for being non zero first, I get a warning about the
compare, ie it doesn't like:
if (ref($myfoo) eq 'Foo')
because the 0 returned at runtime when $myfoo is NOT an object makes the
compare undefined. At the very least this runs counter to the examples in
the manual or else implies that you always KNOW that myfoo is a pointer.
2) If
{$myfoo = $myfoo->doSomething ( 'data' => $data );
is instead written as the more normal (for me!):
{$myfoo = doSomething $myfoo ( 'data' => $data );
it fails at load time. claiming a syntax error near "$myfoo ("
3) Similarly, if
{$myfoo = new Foo
('data' => $data, 'filename' => $filename);
instead uses the $type argument of the method instead of being explicitly
defined:
{$myfoo = new $type
('data' => $data, 'filename' => $filename);
It collect the same sort of load time warning.
I'm curious as to the why's because even if wrong, the code seems
intuitively correct, which makes me wonder about underlying syntax...
fragment of a Class method has to be written just so to avoid load
and/or run time complaints:
if (ref($myfoo) && (ref($myfoo) eq 'Foo'))
{$myfoo = $myfoo->doSomething ( 'data' => $data );
}
else
{$myfoo = new Foo
('data' => $data, 'filename' => $filename);
}
1) If I don't test the ref for being non zero first, I get a warning about the
compare, ie it doesn't like:
if (ref($myfoo) eq 'Foo')
because the 0 returned at runtime when $myfoo is NOT an object makes the
compare undefined. At the very least this runs counter to the examples in
the manual or else implies that you always KNOW that myfoo is a pointer.
2) If
{$myfoo = $myfoo->doSomething ( 'data' => $data );
is instead written as the more normal (for me!):
{$myfoo = doSomething $myfoo ( 'data' => $data );
it fails at load time. claiming a syntax error near "$myfoo ("
3) Similarly, if
{$myfoo = new Foo
('data' => $data, 'filename' => $filename);
instead uses the $type argument of the method instead of being explicitly
defined:
{$myfoo = new $type
('data' => $data, 'filename' => $filename);
It collect the same sort of load time warning.
I'm curious as to the why's because even if wrong, the code seems
intuitively correct, which makes me wonder about underlying syntax...