dear lazyweb: hashref instead of objects

[email protected] (Ricardo SIGNES)
Newsgroups perl.moose
Message-ID <[email protected]>
This is a quick sketch of an idea I was having today, written down and sent
into the ether before I get off the bus and forget:

I want a way to coerce any kind of object with the X nature out of a hashref by
having it call Class->new(hashref).  An inflater could handle this for simple
cases.  The problem is that I do not want to write:

  coerce 'Class::A' => from 'HashRef' => via { Class::A->new($_) };
  coerce 'Class::B' => from 'HashRef' => via { Class::B->new($_) };
  coerce 'Class::C' => from 'HashRef' => via { Class::C->new($_) };

If these are all isa Class::Base, I don't know how this could help.  I don't
think even the quietly-muttered-about type coersion cascading is likely to be
useful for this.

I just like the idea of saying:

  my $o = Object->new(
    foo => 1,
    bar => 2,
    obj => {
      quux => 3,
    },
  });

-- 
rjbs
signature.asc (application/pgp-signature, 194 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)

iEYEARECAAYFAkes9SMACgkQHu6P14fNXHOmIgCgmf5y2oqLXd5dfkteavaug1kD
5lwAn0h7dX6uPZSQtxLxD4GUDEGB7kga
=E0Eg
-----END PGP SIGNATURE-----
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.