Stories
Slash Boxes
Comments
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

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
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.

    • And along the lines of what I said earlier, here's my first test case with it:

      #!/usr/bin/perl

      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;
                  my %email = (
                      personal => 'victoria@example.com',
                      work     => 'victoria@some_company.com',
                  );
                  return $email{+shift};
              },
              to_xml => sub {
                  require Some::Class::Bermuda;
                  require Bermuda::XML;
                  return Bermuda::XML->new->render(
                      Some::Class::Bermuda->fetch_data(shift)
                  );
              },
          }
      );
      my $island = <<'END_ISLAND';
      ---
      package: Some::Class
      island: dummy
      name: dummy
      attributes:
        name:
          type: string
      elements:
        - personal_email
        - type: string
          method: email('personal')
        - work_email
        - type: string
          method: email('work')
      END_ISLAND

      Bermuda::Test->build($island);

      my $expected = <<'END_XML';
      <?xml version="1.0" encoding="utf-8"?>
      <dummy name="Victoria">
        <personal_email>victoria@example.com</personal_email>
        <work_email>victoria@some_company.com</work_email>
      </dummy>
      END_XML
      is_xml $dummy->to_xml, $expected,
          'Methods with args should correctly serialize to XML';

      To my mind, that shows me that the &to_xml method is problematic. I can automate that. People need to be able to create a Bermuda project and then make it simple by dropping this into their classes:

      package Some::Company::Invoice;

      use Class::Trait 'Some::Company::Bermuda';

      And then the Some::Company::Invoice class automatically gets a &to_xml method. Already have a &to_xml method?

      package Some::Company::Invoice;

      use Class::Trait (
          'Some::Company::Bermuda' => {
              alias => { to_xml => 'as_xml' },
          }
      );