After reading and working through the Moose Cookbook, I had the following questions after said examples. I would appreciate answers to these questions.
Basic::1 -------- When is clear() called in the object construction sequence? What is the purpose of clear()? I presume to reset an object to default values at anytime, including object construction? What if the class and it's superclass define clear without the subclass using 'override' Why is the fat comma used and yet single quotes around the word 'clear' like so after 'clear' => sub { ... I personally sort of like the quotes because it makes the sub-name stand out more. Basic::2 -------- Is clear() called even if no clear() method is defined? What about BUILD? Comment: the parallel bars form of 'or' should not be used here ... 'or' should also && should not be used ... 'and' should Basic::3 -------- how can I rewrite: default => sub { BinaryTree->new(parent => $_[0]) }, so that it refers to a named sub? Is there more than one way to do so? This is more of a basic Perl question, but there is no such thing as a dumb question! I'm thinking default => \&sub_name, will do the trick. Basic::4 -------- In order to understand BUILD better: - does it always receive a hashref of what ->new() was called with regardless of whether it was called with a hash or hashref? - what is the entire sequence of things that happen when ->new() is called? - in terms of public API hooks and customization, what happens when ->new() is called? The two public hooks appear to be clear() and BUILD() but I can find no docs on exactly when and how each is called. - Moose::Util::TypeConstraints is not needed in package Company is it? Basic::5 -------- - the coerce keyword can coerce from a number of things. If it is coercing from Object, how does it know that $_ is an Object? If it is to coerce from Str, how does it know that $_ is a Str? - After looking through Moose::Util::TypeConstraints, I'm wondering what constitutes an object. Must it be a Moose object? Old-style Perl 5 object? Class::Prototyped object? - a non-declarative, but equivalent way to coerce arrayrefs and hashrefs wouldve been with a default sub like this, correct? sub { my $r = ref $_[0]; if ($r eq 'ARRAY') { HTTP::Headers->new( @{ $_ } ) ; } elsif ($r eq 'HASH) { HTTP::Headers->new( %{ $_ } ) ; } else { HTTP::Headers->new; } }