You are correct the syntax for the code you posted needs the class followed by roles. I initially misread Point as a Role. I tend to put all of the appended roles in a list form though just to improve readability (even if there is just one). Also if you don't like the method call on a method result you can separate them into two and the required=>1, elements of the attributes still won't error.
my $named_point_class = with_traits(
'Point',
(
'Named',
),
);
my $point_instance = $named_point_class->new(
x => 1,
y => 1,
name => 'my_point',
);
Update:If you are using this in boilerplate the role can be a dummy name as well and it still works!
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|