in reply to Re: Need Help Refactoring Method Calls
in thread Need Help Refactoring Method Calls

Wow. I really did think of something like this at first, but I concluded that it would be a soft reference that the 'warnings' pragma wouldn't catch but Perl Lint would. I didn't want to use a fancy soft reference like that.

However, since no one else has commented that what you wrote was a soft reference (even though it still looks like one to me), I decided to run an example thru Perl Lint, and sure enough, it passes.

# cat test_me.pl #!/usr/bin/perl -w use strict; use warnings; use Top::Middle; my $class = "Top::Middle"; my $obj = $class->new( 'info' => 'some_data_or_whatever' ); $obj->method(); exit 0;
# perl -MO=Lint test_me.pl test_me.pl syntax OK

Replies are listed 'Best First'.
Re^3: Need Help Refactoring Method Calls
by rhesa (Vicar) on Feb 02, 2006 at 20:37 UTC
    I don't think we're dealing with soft references here. The $class is just a string. Perl lets you write barewords for package names as well, but really it's just the package name that you're passing around.

    Remember, Foo->new, or $class->new, both translate to new( Foo ) or new( $class ), which is simply passing the string into the new() call.

    (I know, I should probably have written Foo::new('Foo'), plus there's some method dispatching logic buried in the ->, but that doesn't detract from the fact.)