<?xml version="1.0" encoding="windows-1252"?>
<node id="809228" title="Re: About inheritence ? and Autoload ?" created="2009-11-24 18:38:31" updated="2009-11-24 18:38:31">
<type id="11">
note</type>
<author id="381608">
ikegami</author>
<data>
<field name="doctext">
&lt;blockquote&gt;&lt;p&gt;&lt;i&gt;why does &lt;c&gt;my $test_command = Command-&gt;new(@ARGV);&lt;/c&gt; not work ?&lt;/i&gt;&lt;/blockquote&gt;

&lt;p&gt;How does it "not work"? &lt;b&gt;(&lt;/b&gt; Oops, thought it said &lt;c&gt;Test-&gt;new&lt;/c&gt;. You never defined &lt;c&gt;Command::new&lt;/c&gt; &lt;b&gt;)&lt;/b&gt;

&lt;blockquote&gt;&lt;p&gt;&lt;i&gt;I'd like to check if there's a &lt;c&gt;Test::Command::$command&lt;/c&gt; module&lt;/i&gt;&lt;/blockquote&gt;

&lt;c&gt;
my $pkg = "Test::Command::$command";
( my $mod = $pkg ) =~ s{::}{/}g;
$mod .= '.pm';
my $exists = eval { require $mod };
&lt;/c&gt;


&lt;blockquote&gt;&lt;p&gt;&lt;i&gt;and if yes execute something like &lt;c&gt;Test::Command::$command-&gt;handle_output()&lt;/c&gt;&lt;/i&gt;&lt;/blockquote&gt;

&lt;c&gt;
...
$pkg-&gt;handle_output();
&lt;/c&gt;

&lt;p&gt;By the way, &lt;c&gt;Test::Command::new&lt;/c&gt; re-blesses the object for nothing and could use some cleanup:

&lt;c&gt;
sub new {
    my $class   = shift;
    my $command = shift;

    my $self = $class-&gt;SUPER::new();

    print "DEBUG : handling command $command in " . __PACKAGE__ . "\n"
        if ( $command );
}
&lt;/c&gt;
</field>
<field name="root_node">
809222</field>
<field name="parent_node">
809222</field>
</data>
</node>
