in reply to COPE and 'any' data type

The process of creating an instance of type any involves wrapping a bit of data in a two-slot array in which one slot contains the object's TypeCode and the other contains the data to be passed. The TypeCode is necessary for proper marshalling and unmarshalling since the whole point of an any is that it really can be anything at all, but the TypeCode serves as a kind of metadata to bring some sanity to process.

The COPE package provides a constructor for instantiating any's in package CORBA::Any, but you need to provide the correct TypeCode in order for it to work. Based on the IDL supplied, the Perl code would be this:

my $any = new CORBA::Any($CORBA::MyModule::MyData::_tc, $struct);
Update: typo, this should be
my $any = new CORBA::Any($MyModule::MyData::_tc, $struct);
(Only CORBA base types are stored in the CORBA module, e.g., $CORBA::_tc_float;)

Examine the file MyData_types.pm and you'll see the code there that sets the value of the first parameter. For more examples see the COPE test suites, in particular COPE/t/base2.t

Replies are listed 'Best First'.
Re: Re: COPE and 'any' data type
by Anonymous Monk on Jul 03, 2002 at 05:20 UTC

    You have said to use: $CORBA::MyModule::MyData::_tc

    When I use this it doesn't recognise the data type in the Any constructor. It therefore sets the value and type to be null.

    In the examples in the COPE/t/base2.t they use $MyModule::MyData::_tc. This at least seems to run the correct code in the constructor but I then get an error when I run it saying:

    Can't use string ("NONE") as an ARRAY ref while "strict refs" in use at Perl/perllib/COPE/CORBA/Any.pm line 63.

    I know this is to do with symbolic and hard references but I'm not sure what I have to do. This error occurs in the _marshal_any method of Any. I can't seem to see in the example what has been done to allow $MyModule to be used.

    Was there a reason why you used $CORBA and then the package so that it is different to the example?

    Thanks for any help. This seemingly simple problem is driving me mad.

      Ok figured it out. One of the members of MyData was also an Any. This was not being set correctly.

      So the solution was

      my $anyData = new CORBA::Any($MyModule::MyData::_tc, $struct).

      Thanks fever. You got me on the right track.