use Win32::OLE;
my $dict = Win32::OLE->CreateObject("Scripting.Dictionary");
$dict->Count(); # how many Items
$dict->Add( $key, $value);
my $val = $dict->Item($key);
####
use Win32::OLE;
use MooseX::Declare;
class Dictionary {
has '_DictObj' => (
is => 'ro',
isa => 'Object',
required => 1,
handles => [ qw/Count Item Add/ ],
);
};
# somewhere else
my $dict = Dictionary->new(Win32::OLE->CreateObject("Scripting.Dictionary"));
$dict->Add($key, $value);
####
package MyOleTypeLib;
use Moose::Util::TypeConstraints;
sub isDictionary {
my $val = shift;
return 0
unless $val->isa('Win32::OLE');
my @lst = Win32::OLE->QueryObjectType($val);
return ( $lst[0] eq 'TSATLLib' # different for real ...
and $lst[1] eq 'ITSEnt'); # ... VBS dictionary
}
subtype 'Dictionary',
as 'Object',
where { isDictionary($_) },
message { "$_ is not a OLE-Dictionary!"};
# in my Class:
class Dictionary {
has '_DictObj' => (
isa => 'Dictionary',
...
####
class Dictionary {
...
method get_text {
return _DictObj->GetFile(1);
}
method set_text (Str $newtext) {
return _DictObj->SetFile(1, $newtext);
}
####
my $text = $moose_dict->text;
$moose_dict->text($newtext);