using Class::Struct in a module

From: Christopher J. Bottaro (cjbottaro_at_alumni.cs.utexas.edu)
Date: 08/05/04


To: beginners@perl.org
Date: Wed, 04 Aug 2004 17:35:29 -0500

package My::Module;
use Class::Struct;

struct Blah => {
        field1 => '$',
        field2 => '$'
};

sub new {
        # normal constructor
}

sub f {
        my $s = new Blah; # this calls new() defined above
        $s->field1 = 1;
        $s->field2 = 2;
        return $s;
}

package main;

my $obj = new My::Module;
my $s = $obj->f();
print "$s->field1\n$s->field2\n";

---------------------------------------------

ok, the problem is that in My::Module::f(), the statement my '$s = new Blah'
calls My::Module::new() instead of constructing a struct of type Blah. how
can i get this code to perform the way i want?

thank you for the help.



Relevant Pages

  • SSIS - Adding Mappings Programatically
    ... I am stuck with Adding Mappings, ... '// Here is subset of my sample code ... Sub SSISPackageDemo() ... Savepackage(pkg, True) '//Save Package to SQL Server ...
    (microsoft.public.sqlserver.dts)
  • Re: best practice ... requires
    ... affect the way Perl parses your program, like strict and warnings). ... Do you know what calling a sub with & does? ... so you can see that my package is nested and I am now wondering how ...
    (comp.lang.perl.misc)
  • Re: perl menubased user interface
    ... actually use a perl package OR a hash for this, In a "perl package" ... sub map_method { ... # and they're all shell commands. ... Do whatever you want to wrap a shell command. ...
    (comp.lang.perl.misc)
  • Re: Using a DBI connection in many places (in the code)
    ... # non-exported package globals go here ... sub set_name { ... nothing to do with DBI. ...
    (comp.lang.perl.modules)
  • Perl-5.8.2 NDBM_File appears to insert POD into DB file?
    ... sub STORE { ... these methods should be defined by the package inheriting from ... sub NEXTKEY } ... =head2 Exporting without using Exporter's import method ...
    (comp.lang.perl.misc)