hash of objects inside an instance

[email protected] (Erik Colson)
Newsgroups perl.moose
Message-ID <[email protected]>
Hi,

I have two classes : Employee and Department
every Employee works for at least one department. Sometimes the cost is distributed over 2 or more departments. So I'd want a hashref inside the Employee in which the keys are Department instances and the value a percentage to be attributed to that Department.

I tried as follow:

    package Employee;

    has 'departments' => (is=>'ro', isa=>'hashref[Department]', default=>{{}});

(I used traits also, but that doesn't really change the problem...)

so know I can use:

    $an_employee -> departments -> {$a_department} = 100;

and also use the same for retrieving the value, which works.

The content of the $an_employee -> departments is a hash containing keys like:
'Department=HASH(0x7fa823c87b48)'

What bothers me then is that I can't use this string as a Department object and i.e. send a message to a key object of the departments hashref of an Employee.

How can I achieve this ?
--
erik
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.