G'day jjyoung,

Welcome to the monastery.

The short answer may simply be what the error message is telling you. An instance of GenericCommandHandler IS-A GenericCommandHandler and IS-A CoRHandler (both of which are classes), but it IS-NOT-A ChainOfResponsibilityIf which is a role.

If that doesn't answer your question, then a longer answer may require some further input from you.

I created a './PM/1081903/ directory and populated it with:

$ cat ChainOfResponsibilityIf.pm package PM::1081903::ChainOfResponsibilityIf; use Moose::Role; requires 'handleRequest'; requires 'addHandler'; 1;
$ cat CoRHandler.pm package PM::1081903::CoRHandler; use Moose; use Carp qw(confess croak); with 'PM::1081903::ChainOfResponsibilityIf'; sub handleRequest { 1 } sub addHandler { 1 } sub _processCommand { 1 } 1;
$ cat GenericCommandHandler.pm package PM::1081903::GenericCommandHandler; use Moose; extends 'PM::1081903::CoRHandler'; override '_processCommand' => sub { }; 1;
$ cat GCHSuccessor.pm package PM::1081903::GCHSuccessor; use Moose; has 'successor' => ( is => 'rw', isa => 'PM::1081903::ChainOfResposibilityIf', ); 1;

I then ran this script:

#!/usr/bin/env perl use strict; use warnings; use PM::1081903::GenericCommandHandler; use PM::1081903::GCHSuccessor; my $gchs = PM::1081903::GCHSuccessor::->new( successor => PM::1081903::GenericCommandHandler::->new() );

I got a lot of error output which started the same as you reported "Attribute (successor) does not pass the type constraint ...". See the spoiler for the full message.

I then changed this line in GCHSuccessor.pm

isa => 'PM::1081903::ChainOfResposibilityIf',

to

isa => 'PM::1081903::CoRHandler',

I reran the same script and no output at all was generated. Perhaps this is the (type of) change you need.

I then added this line to the end of that script:

print $gchs->successor->handleRequest(), "\n";

This produced 1 as its only output. So, the value of the successor attribute of the PM::1081903::GCHSuccessor object DOES the PM::1081903::ChainOfResposibilityIf role. Is that what you were trying to test?

If some, or all, of that hasn't answered your question, or my guesses at your class stucture were wrong, please provide actual code that we can run, along with a clear description of what trying to test or learn, such that we can point you in the right direction.

-- Ken


In reply to Re: Moose roles with extends by kcott
in thread Moose roles with extends by jjyoung

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.