我应该如何在 Perl 中维护我的对象模块?

发布于 2024-09-28 09:36:13 字数 220 浏览 0 评论 0原文

我正在使用 Moose 在 Perl 中编写一些对象模块。我用来存储创建的对象的实例,然后使用它们。

我的对象数据的基本表示保持不变,但我会不时添加更多功能 - 例如类方法或对象方法。

我可以继续使用使用早期版本的模块创建的具有新功能的存储对象吗?或者每次更改模块时都必须重新创建对象吗?

开发基本数据结构不变但功能发生变化的对象模块的常见范例是什么?

I'm writing some object module in Perl using Moose. I use to store instances of created objects then use them.

The basic representation of my object's data remains the same, but from time to time I add more functionalities - e.g. class methods or object methods.

Can I continue using my stored objects, which were created with an earlier version of the module, with the new functionalities? Or must I create the objects again every time I change the module?

What is the common paradigm for developing an object module where the basic data structure does not change but functionalities do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情痴 2024-10-05 09:36:13

只要数据结构不改变,你就应该没问题:数据被吸收并重新放入你的类的命名空间中:这确保了新方法可用于该数据。

但要小心改变数据结构!

我不认为它有什么问题,尽管对于某些用途,您可以只使用数据库来存储数据,并使用众多 ORM 之一(DBIx::Class、Fey::ORM 或任何一个)以 OO 方式访问它)。

As long as the data structure doesn't change, you should be fine: the data is slurped and reblessed into your class' namespace: this ensures new methods would be available on that data.

BEWARE changing the data structure though!

I don't see much wrong with it, although for some uses you could just use a database to store your data, and access it in a OO fashion using one of the many ORM (DBIx::Class, Fey::ORM or whichever).

爱的那么颓废 2024-10-05 09:36:13

尝试一下KiokuDB。这可能正是你想要的;根据链接的网站:

KiokuDB 是一个基于 Moose 的面向对象的持久性前端,适用于许多存储后端。

Give KiokuDB a whirl. It might be just what you want; according to the site linked:

"KiokuDB is a Moose based object oriented persistence frontend for a number of storage backends."

暖阳 2024-10-05 09:36:13

我赞同查看 KiokuDB 的建议。

除了将 Moose 对象透明序列化到图形存储之外,它还具有处理类版本之间转换的功能。实际上,您可以定义一个翻译例程,将类的版本从 0.1 版本转换到 0.2 版本,并将迁移工作交给它。 KiokuDB 将执行此例程并允许您重新存储结果。

I second the recommendation for looking at KiokuDB.

In addition to transparent serialization of Moose objects to a graph store, it also has a facility for handling transitions between Class versions. Effectively you can define a translation routine to go from version 0.1 to 0.2 of your class and hand the migration off to it. KiokuDB will execute this routine and allow you to re-store the result.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文