Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am using COPE and am having trouble finding documentation on it (other than the 'We Cope' mail archives).
I have a structure in an IDL and I need to convert it to a CORBA any so it can be pushed onto an event channel. How do
I do this conversion? So in the IDL I have :
struct MyData { string key; unsigned long value1; any state; };
I have filled this structure in my Perl script and now want to convert it to a CORBA::Any. This should be simple but I'm missing something.

Thanks in advance

Replies are listed 'Best First'.
Re: COPE and 'any' data type
by BrowserUk (Patriarch) on Jul 02, 2002 at 07:05 UTC

    Warning:I didn't know what COPE was till I read your post.

    I went looking cos I wondered and found this which I think might help. Search on the page for "X.4.7 Anys".

    Sorry if you've already seen it or it's a bum steer.

Re: COPE and 'any' data type
by djantzen (Priest) on Jul 02, 2002 at 13:10 UTC

    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

      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.