RE: using Class::Struct in a module

2004-08-05 Thread NYIMI Jose \(BMB\)


 -Original Message-
 From: news [mailto:[EMAIL PROTECTED] On Behalf Of 
 Christopher J. Bottaro
 Sent: Thursday, August 05, 2004 12:35 AM
 To: [EMAIL PROTECTED]
 Subject: using Class::Struct in a module
 
 
 package My::Module;
 use Class::Struct;

use strict;
use warnings;

 
 struct Blah = {
 field1 = '$',
 field2 = '$'
 };
 
 sub new {
 # normal constructor
 }

I suppose you have some code in the above new() :-)

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

The syntax should be:
$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;

Better putting $s outside of double quote:
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?

Below is your code reviewed:

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

struct( Blah = { field1 = '$', field2 = '$'} );

sub new {
my($caller)[EMAIL PROTECTED];
print normal constructor called!\n;
  my $class=ref $caller || $caller;
  my $self = {};
  bless $self = $class;   
}

sub f {
my $s = Blah-new();
$s-field1(1);
$s-field2(2);
return $s;
}

package main;

my $obj =My::Module-new();
my $s = $obj-f();

print $s-field1.\n.$s-field2.\n;


OUTPUT:

normal constructor called!
1
2


HTH,

José.


 DISCLAIMER 

This e-mail and any attachment thereto may contain information which is confidential 
and/or protected by intellectual property rights and are intended for the sole use of 
the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, total or 
partial reproduction, communication or distribution in any form) by other persons than 
the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by 
telephone or by e-mail and delete the material from any computer.

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at 
http://www.proximus.be or refer to any Proximus agent.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: using Class::Struct in a module

2004-08-05 Thread Christopher J. Bottaro
thank you.  i guess when i was saying 'my $s = new FHEAD', it was calling
the new() in the current package.  changing it to 'my $s = FHEAD-new()'
forces it to use FHEAD's new() method.

NYIMI Jose (BMB) wrote:

 
 
 -Original Message-
 From: news [mailto:[EMAIL PROTECTED] On Behalf Of
 Christopher J. Bottaro
 Sent: Thursday, August 05, 2004 12:35 AM
 To: [EMAIL PROTECTED]
 Subject: using Class::Struct in a module
 
 
 package My::Module;
 use Class::Struct;
 
 use strict;
 use warnings;
 
 
 struct Blah = {
 field1 = '$',
 field2 = '$'
 };
 
 sub new {
 # normal constructor
 }
 
 I suppose you have some code in the above new() :-)
 
 
 sub f   {
 my $s = new Blah; # this calls new() defined above
 $s-field1 = 1;
 $s-field2 = 2;
 
 The syntax should be:
 $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;
 
 Better putting $s outside of double quote:
 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?
 
 Below is your code reviewed:
 
 package My::Module;
 use strict;
 use warnings;
 use Class::Struct;
 
 struct( Blah = { field1 = '$', field2 = '$'} );
 
 sub new {
 my($caller)[EMAIL PROTECTED];
 print normal constructor called!\n;
   my $class=ref $caller || $caller;
   my $self = {};
   bless $self = $class;
 }
 
 sub f {
 my $s = Blah-new();
 $s-field1(1);
 $s-field2(2);
 return $s;
 }
 
 package main;
 
 my $obj =My::Module-new();
 my $s = $obj-f();
 
 print $s-field1.\n.$s-field2.\n;
 
 
 OUTPUT:
 
 normal constructor called!
 1
 2
 
 
 HTH,
 
 Jos.
 
 
  DISCLAIMER 
 
 This e-mail and any attachment thereto may contain information which is
 confidential and/or protected by intellectual property rights and are
 intended for the sole use of the recipient(s) named above. Any use of the
 information contained herein (including, but not limited to, total or
 partial reproduction, communication or distribution in any form) by other
 persons than the designated recipient(s) is prohibited. If you have
 received this e-mail in error, please notify the sender either by
 telephone or by e-mail and delete the material from any computer.
 
 Thank you for your cooperation.
 
 For further information about Proximus mobile phone services please see
 our website at http://www.proximus.be or refer to any Proximus agent.
 
 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response