in reply to Re: Is it a reference issue or what?
in thread Is it a reference issue or what?

Yeah well, it's a work in progress. The class actually instantiates a Win32_Drive object. The global hash and array I will fix later to make them private. $$self->FreeSpace is used. It is a method of the Win32_Drive class that is blessed into the class

So what I'm trying to do is bless the Win32_Drive class returned by a WMI query so I can add other methods to it.

The CIM_Datafile collection ($file returned by WMI) is supposed to be of various .bak and .trn files found in that drive.

Because the .trn files are on different drives to the .bak files I want multiple Backup_Drives that are holding their own collection of files. Then I can work out the calculations where they have to cross reference each other for information later.

It's complicated.

Replies are listed 'Best First'.
Re^3: Is it a reference issue or what?
by Corion (Patriarch) on Jan 28, 2010 at 07:55 UTC

    I doubt that reblessing a Win32::OLE object will work as you intend it to, because Win32::OLE objects live mainly in C/XS space. I recommend you aggregate the WMI object instead of trying to extend it, and delegate all unknown methods to the WMI object via AUTOLOAD:

    sub AUTOLOAD { my $self = shift; (my $meth = $AUTOLOAD) =~ s/.*::/; # Now call the method on the WMI object $self->{wmi}->$meth(@_); }

    The above method could be refined further to play with the stack so that all error messages point to the real caller instead of the reflection method, but for a first stab, this approach is OK.

      That's a cool idea! I'll try that. Thanks.