Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

  (email not shown publicly)
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Thursday January 31, 2008
06:54 AM


[ #35535 ]

If I want to serialize arbitrary classes with Bermuda, I need to make arbitrary classes (and instances of them. I looked for something useful, but I'm not seeing it. Currently I'm writing the following:

ok my $dummy = Class::Dummy->new(
    package => 'Foo::Bar',
    methods => {
        first_name => 'bob',
        last_name  => 'marley',
        aref       => [ 1,2,3 ],
        list       => sub { ( 3, 4, 5 ) },
        full_name  => sub {
            my $self = shift;
            return join ' ' => map { $self->$_ } qw/ first_name last_name /;
), '... creating a dummy class should succeed';

isa_ok $dummy, 'Class::Dummy', '... and the object it returns';
can_ok $dummy, 'first_name';
is $dummy->first_name, 'bob';

Please let me know if this already exists.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • You could nearly call that Class::Inner and have it work like Java's inner classes :)

    Which IMO might be a useful thing. Inner classes definitely have their uses - maybe more so in Java.

    • I was thinking of this more as a testing tool so that I could generate fixtures on the fly and embed them in tests:

      my $instance   = Class::Dummy->new(\%interface);
      my @islands    = @yaml_strings;
      my $serialized = Bermuda::Test->serialize($instance, @islands);

      # a bunch of tests

      A persistent problem with test suites is having fixtures embedded in files and the poor programmer has to pop between several files to see them. That also means that a change to one fixture possibly means

      • Sorry - being terse today :)

        I realised what it was for but it occurred to me that it might sometimes be useful outside of tests.

        • Maybe I should rename it then? It really does seem like a useful testing tool (it's already making my life easier), but perhaps others could use it. Does Class::Temp sound like a good name? It would be very useful when you find yourself passing around hashrefs but you hate locked hashes.

          • I think Class::Inner is a similar but different thing that you can release once you get all the other interesting things you're working on done :)
    • And along the lines of what I said earlier, here's my first test case with it:


      use strict;
      use warnings;

      use lib 'lib', 't/lib';
      use Test::Most 'no_plan'; # tests => 1;
      use Test::XML;
      use Bermuda::Test;
      use Bermuda::XML;
      use Class::Dummy;

      my $dummy = Class::Dummy->new(
          package => 'Some::Class',
          methods => {
              name => 'Victoria',
              email => sub {
                  my $self = shift;

  • There's Class::Generate, which looks pretty weird to me. I use (wrote) Package::Generator, which has no method sugar. You can use Class::MOP, too, as seen here: []