kasei / attean

A Perl Semantic Web Framework
19 stars 10 forks source link

Croak if mixing up second argument to cost_for_plan #77

Closed kjetilk closed 8 years ago

kjetilk commented 8 years ago

Since the bugs caused by mixing up the second argument, plan/model to cost_for_plan causes pretty obscure problems, I think we should make it croak if that happens. I looked into it (and therefore started feature-cost-ensure-planner), but then I became unsure how to do it... Since you can't just check does('Attean::API::CostPlanner') since they both do that. It could be implemented in that role, but would we check isa('Attean::QueryPlanner'), etc? That would then mean that all query planners would extend that instead of just composing everything...

kasei commented 8 years ago

Where do you want this check to happen? In the planner? Or the model? I can think of a few different options here:

kjetilk commented 8 years ago

It seems the latter option isn't very attractive, since what the model and the planner does in this regard is very similar, and so should be a single role.

I think both the planner and the model should check, and it sounds like a reasonable check that they aren't the same time and only one is a model object.

kasei commented 8 years ago

They're very similar, yes. But models don't have to return a cost for all plans. They have the option of returning undef and letting the upstream planner handle it. The upstream planner is required to generate costs for all plans. That seems like a relevant difference, doesn't it?

For now, I can add the checks about the two objects not being the same.

kjetilk commented 8 years ago

Right, that's a good point! Any of them would have caught the previous error, so it works for me. Thanks!

kjetilk commented 8 years ago

Yup, this looks good. Would have caught the problem for sure!