No subject


Thu Jul 7 17:32:24 GMT 2022


one time to pass constraint objects to Args().=C2=A0 I'm not sure at
what point it stopped working, or if it still works, and I need to
do something differently to enable it.

=C2=A0 =C2=A0 package MyApp::Controller::MyController;

=C2=A0 =C2=A0 use Moose;
=C2=A0 =C2=A0 use MooseX::MethodAttributes;
=C2=A0 =C2=A0 use Types::Standard qw(Int);

=C2=A0 =C2=A0 use namespace::autoclean;

=C2=A0 =C2=A0 sub view : PathPart('view') Args(Int) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 my ( $self, $c ) =3D @_;

=C2=A0 =C2=A0 =C2=A0 =C2=A0 $c->stash->{template} =3D 'foo.tt';
=C2=A0 =C2=A0 =C2=A0 =C2=A0 $c->forward( 'MyApp::View::TT' );
=C2=A0 =C2=A0 }

When I add some debugging to resolve_type_constraint() in
Catalyst::Action, I find that what is received is not an object,
even though we check to see if it is an object.

The code that evals the package and tries to instantiate the type
object also does not appear to be successful.

=C2=A0 =C2=A0 sub resolve_type_constraint {
=C2=A0 =C2=A0 =C2=A0 my ($self, $name) =3D @_;
=C2=A0 =C2=A0=20
=C2=A0 =C2=A0 =C2=A0 if(defined($name) && blessed($name) && $name->can('che=
ck')) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 # Its already a TC, good to go.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 warn "$name is a type constraint\n";
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return $name;
=C2=A0 =C2=A0 =C2=A0 }
=C2=A0 =C2=A0=20
=C2=A0 =C2=A0 =C2=A0 warn "$name is " . (defined($name) ? '' : 'NOT') . " d=
efined\n";
=C2=A0 =C2=A0 =C2=A0 warn "$name is " . (blessed($name) ? '' : 'NOT') . " b=
lessed\n";
=C2=A0 =C2=A0 =C2=A0 warn "$name can " . ($name->can('check') ? '' : 'NOT')=
 . " check\n";
=C2=A0 =C2=A0 =C2=A0 # This is broken for when there is more than one const=
raint
=C2=A0 =C2=A0 =C2=A0 if($name=3D~m/::/) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 eval "use Type::Registry; 1" || die "Can't reso=
lve type constraint $name without installing Type::Tiny";
=C2=A0 =C2=A0 =C2=A0 =C2=A0 my $tc =3D=C2=A0 Type::Registry->new->foreign_l=
ookup($name);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return defined $tc ? $tc : die "'$name' not a f=
ull namespace type constraint in ${\$self->private_path}";
=C2=A0 =C2=A0 =C2=A0 }
=C2=A0 =C2=A0 =C2=A0=20
=C2=A0 =C2=A0 =C2=A0 my @tc =3D grep { defined $_ } (eval("package ${\$self=
->class}; $name"));
=C2=A0 =C2=A0 =C2=A0 warn "$name eval'ed within " . $self->class . " become=
s:"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 . join(', ', map { defined($_) ? "'$_'" =
: undef } @tc) .=C2=A0 "\n";

=C2=A0 =C2=A0 =C2=A0 ...
=C2=A0 =C2=A0 }

The output I get is:

=C2=A0 =C2=A0 Int is=C2=A0 defined
=C2=A0 =C2=A0 Int is NOT blessed
=C2=A0 =C2=A0 Int can NOT check
=C2=A0 =C2=A0 Int eval'ed within MyApp::Controller::MyController becomes:

with no values displayed.

I'd really like to be able to use this functionality.=C2=A0 Any
suggestions for what I might try?

-kolibrie
_______________________________________________
List: Catalyst at lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
 =20
------=_Part_1948278_1694038692.1659031211102
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<html><head></head><body><div class=3D"ydpb6822d5fyahoo-style-wrap" style=
=3D"font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:13px=
;"><div></div>
        <div dir=3D"ltr" data-setdir=3D"false">Try removing use namespace::=
autoclean;</div><div><br></div>
       =20
        </div><div id=3D"yahoo_quoted_9214545528" class=3D"yahoo_quoted">
            <div style=3D"font-family:'Helvetica Neue', Helvetica, Arial, s=
ans-serif;font-size:13px;color:#26282a;">
               =20
                <div>
                    On Thursday, May 12, 2022, 04:01:49 PM CDT, Nathan Gray=
 &lt;kolibrie at cpan.org&gt; wrote:
                </div>
                <div><br></div>
                <div><br></div>
                <div>I found a fascinating feature documented at <a href=3D=
"https://metacpan.org/pod/Catalyst::Controller#Args" target=3D"_blank">http=
s://metacpan.org/pod/Catalyst::Controller#Args</a><br>and <a href=3D"https:=
//metacpan.org/dist/Catalyst-Runtime/view/lib/Catalyst/RouteMatching.pod#Ty=
pe-Constraints-in-Args-and-Capture-Args" target=3D"_blank">https://metacpan=
.org/dist/Catalyst-Runtime/view/lib/Catalyst/RouteMatching.pod#Type-Constra=
ints-in-Args-and-Capture-Args</a><br>where you can provide a Type::Tiny or =
other constraint object to<br>Args() or CaptureArgs() instead of specifying=
 the number of<br>arguments to capture as an integer.<br><br>However, when =
I tried it out, I found that even though the<br>documentation and the Catal=
yst code (in Catalyst::Action<br>resolve_type_constraint()) make it clear t=
hat a type object is<br>expected, what is actually received is a string.<br=
><br>Looking deeper, it appears that <a href=3D"https://metacpan.org/pod/Mo=
oseX::MethodAttributes" target=3D"_blank">https://metacpan.org/pod/MooseX::=
MethodAttributes</a><br>is used to retrieve the parameters provided to Args=
(), and its<br>documentation shows that only a string will be passed throug=
h.<br><br>From the Catalyst documentation, it seems like it was possible at=
<br>one time to pass constraint objects to Args().&nbsp; I'm not sure at<br=
>what point it stopped working, or if it still works, and I need to<br>do s=
omething differently to enable it.<br><br>&nbsp; &nbsp; package MyApp::Cont=
roller::MyController;<br><br>&nbsp; &nbsp; use Moose;<br>&nbsp; &nbsp; use =
MooseX::MethodAttributes;<br>&nbsp; &nbsp; use Types::Standard qw(Int);<br>=
<br>&nbsp; &nbsp; use namespace::autoclean;<br><br>&nbsp; &nbsp; sub view :=
 PathPart('view') Args(Int) {<br>&nbsp; &nbsp; &nbsp; &nbsp; my ( $self, $c=
 ) =3D @_;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; $c-&gt;stash-&gt;{template} =
=3D 'foo.tt';<br>&nbsp; &nbsp; &nbsp; &nbsp; $c-&gt;forward( 'MyApp::View::=
TT' );<br>&nbsp; &nbsp; }<br><br>When I add some debugging to resolve_type_=
constraint() in<br>Catalyst::Action, I find that what is received is not an=
 object,<br>even though we check to see if it is an object.<br><br>The code=
 that evals the package and tries to instantiate the type<br>object also do=
es not appear to be successful.<br><br>&nbsp; &nbsp; sub resolve_type_const=
raint {<br>&nbsp; &nbsp; &nbsp; my ($self, $name) =3D @_;<br>&nbsp; &nbsp; =
<br>&nbsp; &nbsp; &nbsp; if(defined($name) &amp;&amp; blessed($name) &amp;&=
amp; $name-&gt;can('check')) {<br>&nbsp; &nbsp; &nbsp; &nbsp; # Its already=
 a TC, good to go.<br>&nbsp; &nbsp; &nbsp; &nbsp; warn "$name is a type con=
straint\n";<br>&nbsp; &nbsp; &nbsp; &nbsp; return $name;<br>&nbsp; &nbsp; &=
nbsp; }<br>&nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; warn "$name is " . (defin=
ed($name) ? '' : 'NOT') . " defined\n";<br>&nbsp; &nbsp; &nbsp; warn "$name=
 is " . (blessed($name) ? '' : 'NOT') . " blessed\n";<br>&nbsp; &nbsp; &nbs=
p; warn "$name can " . ($name-&gt;can('check') ? '' : 'NOT') . " check\n";<=
br>&nbsp; &nbsp; &nbsp; # This is broken for when there is more than one co=
nstraint<br>&nbsp; &nbsp; &nbsp; if($name=3D~m/::/) {<br>&nbsp; &nbsp; &nbs=
p; &nbsp; eval "use Type::Registry; 1" || die "Can't resolve type constrain=
t $name without installing Type::Tiny";<br>&nbsp; &nbsp; &nbsp; &nbsp; my $=
tc =3D&nbsp; Type::Registry-&gt;new-&gt;foreign_lookup($name);<br>&nbsp; &n=
bsp; &nbsp; &nbsp; return defined $tc ? $tc : die "'$name' not a full names=
pace type constraint in ${\$self-&gt;private_path}";<br>&nbsp; &nbsp; &nbsp=
; }<br>&nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; my @tc =3D grep { defi=
ned $_ } (eval("package ${\$self-&gt;class}; $name"));<br>&nbsp; &nbsp; &nb=
sp; warn "$name eval'ed within " . $self-&gt;class . " becomes:"<br>&nbsp; =
&nbsp; &nbsp; &nbsp; &nbsp; . join(', ', map { defined($_) ? "'$_'" : undef=
 } @tc) .&nbsp; "\n";<br><br>&nbsp; &nbsp; &nbsp; ...<br>&nbsp; &nbsp; }<br=
><br>The output I get is:<br><br>&nbsp; &nbsp; Int is&nbsp; defined<br>&nbs=
p; &nbsp; Int is NOT blessed<br>&nbsp; &nbsp; Int can NOT check<br>&nbsp; &=
nbsp; Int eval'ed within MyApp::Controller::MyController becomes:<br><br>wi=
th no values displayed.<br><br>I'd really like to be able to use this funct=
ionality.&nbsp; Any<br>suggestions for what I might try?<br><br>-kolibrie<b=
r>_______________________________________________<br>List: <a ymailto=3D"ma=
ilto:Catalyst at lists.scsys.co.uk" href=3D"mailto:Catalyst at lists.scsys.co.uk"=
>Catalyst at lists.scsys.co.uk</a><br>Listinfo: <a href=3D"http://lists.scsys.=
co.uk/cgi-bin/mailman/listinfo/catalyst" target=3D"_blank">http://lists.scs=
ys.co.uk/cgi-bin/mailman/listinfo/catalyst</a><br>Searchable archive: <a hr=
ef=3D"http://www.mail-archive.com/catalyst@lists.scsys.co.uk/" target=3D"_b=
lank">http://www.mail-archive.com/catalyst@lists.scsys.co.uk/</a><br>Dev si=
te: <a href=3D"http://dev.catalyst.perl.org/" target=3D"_blank">http://dev.=
catalyst.perl.org/</a><br></div>
            </div>
        </div></body></html>
------=_Part_1948278_1694038692.1659031211102--



More information about the Catalyst mailing list