This is my first Moose experiment. Suggestions for improvement are welcome.

In this code, class ThreeD has a class variable $active_model. $active_model is a ThreeD::Model object which has an $active_entities variable.

On line 19, ThreeD::Model->new() is called, but the constructor is never actually run. Line 20 attempts to get the active_entities from the new model, but fails saying that there is no active_entities method in ThreeD::Model.

Expected output:

DEBUG DEBUG3 DEBUG2 DEBUG2a DEBUG1a

Actual output:

DEBUG Can't locate object method "active_entities" via package "ThreeD::Mode +l" at /home/john/workspace/TestOOP/MY/ThreeD.pm line 13.

The code:

#!/usr/bin/perl # package ThreeD; use Moose; use MooseX::ClassAttribute; use namespace::autoclean; class_has 'active_model' => (isa => 'Model', is => 'ro', default => sub {print "DEBUG\n"; my $model = ThreeD::Mo +del->new(); my $entities = $model- +>active_entities; print "DEBUG 1a\n"; return $model}); __PACKAGE__->meta->make_immutable; no Moose; no MooseX::ClassAttribute; 1; { package ThreeD::Model; use Moose; use namespace::autoclean; has 'active_entities' => (isa => 'Entities', is => 'ro', lazy => 0, default => sub {print "DEBUG 2\n"; my $entities = ThreeD::E +ntities->new(); print "DEBUG 2b\n"; return $entities}); around BUILDARGS => sub { my ($orig, $class, %args) = @_; print "DEBUG 3\n"; return $class->$orig(%args); }; __PACKAGE__->meta->make_immutable; 1; } { package ThreeD::Entity; use Moose; use namespace::autoclean; use MooseX::FollowPBP; my $my_index = 0; has 'entityID' => (isa => 'Int', is => 'ro', required => 1); around BUILDARGS => sub { my ($orig, $class, %args) = @_; $args{entityID} = $my_index; $my_index++; return $class->$orig(%args); }; __PACKAGE__->meta->make_immutable; 1; } { package ThreeD::Entities; use Moose; use namespace::autoclean; #use MooseX::FollowPBP; use OpenGL; has 'entity' => (isa => 'ArrayRef[ThreeD::Entity]', is => 'rw', default => sub {[]}); __PACKAGE__->meta->make_immutable; 1; } package main; use strict; use warnings; my $model = ThreeD->active_model; my $entities = $model->active_entities;

In reply to Moose class not being constructed by SwaJime

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.