perlquestion
bv
<p>Hoping someone can straighten me out. I'm trying to do this the right way, so if there's a better way, I'd love to hear it.</p>
<p>I wrote a Model for my [mod://Catalyst] app that just loads a YAML file and provides accessors and validation. I copied some code from [mod://Catalyst::Model::DBI], specifically the code for <c>new</c>, but I'm getting warnings about my use of [doc://NEXT].</p>
<readmore>
<c>package Clio::Model::YAML;
use namespace::autoclean;
use base 'Catalyst::Model';
use MRO::Compat;
use Data::Dumper;
use YAML::Any qw(LoadFile);
use warnings;
use strict;
__PACKAGE__->mk_accessors('defs');
sub new
{
my $class = shift;
my $self = $class->NEXT::new(@_);
$self->{defs} = mergekeys( LoadFile "db/clio.yml" );
return $self;
}</c>
<p>The error I get is this:</p>
<c>$ ./script/clio_test.pl
Clio::Model::YAML uses NEXT, which is deprecated. Please see the Class::C3::Adopt::NEXT documentation for details. NEXT used at /home/miller/actions/note_taker/Clio/script/../lib/Clio/Model/YAML.pm line 16</c>
<p>I read the documentation, and tried to follow it (hence the <c>use MRO::Compat</c> above). It says,</p>
<blockquote>You add use MRO::Compat to the top of a package as you start converting it, and gradually replace your calls to NEXT::method() with maybe::next::method(), and calls to NEXT::ACTUAL::method() with next::method().</blockquote>
<p>but when I change my code to <c>my $self = $class->maybe::next::new(@_);</c> I get this error:</p>
<c>Couldn't load class (Clio) because: Couldn't instantiate component "Clio::Model::YAML", "Can't locate object method "new" via package "maybe::next" at /home/miller/actions/note_taker/Clio/script/../lib/Clio/Model/YAML.pm line 16."Compilation failed in require at /usr/local/lib/perl/5.10.1/Class/MOP.pm line 98.</c>
<p>Am I reading this wrong? How am I supposed to do this under C3? Thanks for any help you can give.</p>
</readmore>
<p><em>UPDATE:</em> Solved the problem. Short version: should be <em>literally</em> <c>$class->maybe::next::method(@_)</c>. See my response below for details.</p>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-790588">
<hr><code>print map{substr'hark, suPerJacent other l',$_,1}(11,7,6,16,5,1,15,18..23,8..10,24,17,0,12,13,3,14,2,4);
</code>
</div></div>