DBIx-Class-InflateColumn-Serializer-0.10 000755 001750 001750 0 15171041725 17632 5 ustar 00mruiz mruiz 000000 000000 TODO 100644 001750 001750 670 15171041725 20366 0 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10 TODO list for Perl module DBIx::Class::InflateColumn::Serializer
- Make tests detect what serializers you have installed, and test only those
- Truncation tests now have to manually be executed against a mysql that has the table in t/lib/sqlite.sql
created DBICTEST_DSN="dbi:mysql:test" DBICTEST_NODEPLOY=1 perl -I blib/lib/ t/002_serialize.t
- Let the user select the parameters for serialization modules (via serializer_args, f. ex.)
README 100644 001750 001750 4733 15171041725 20602 0 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10 NAME
DBIx::Class::InflateColumn::Serializer - Inflators to serialize data
structures for DBIx::Class
SYNOPSIS
package MySchema::Table;
use base 'DBIx::Class';
__PACKAGE__->load_components('InflateColumn::Serializer', 'Core');
__PACKAGE__->add_columns(
'data_column' => {
'data_type' => 'VARCHAR',
'size' => 255,
'serializer_class' => 'JSON'
}
);
Then in your code...
my $struct = { 'I' => { 'am' => 'a struct' };
$obj->data_column($struct);
$obj->update;
And you can recover your data structure with:
my $obj = ...->find(...);
my $struct = $obj->data_column;
The data structures you assign to "data_column" will be saved in the
database in JSON format.
DESCRIPTION
These modules help you store and access serialized data structures in
the columns of your DB from your DBIx::Classes. They are inspired from
the DBIx::Class::Manual::FAQ and the DBIC test suite, and provide a bit
more protection than the inflators proposed in the FAQ. The intention
is to provide a suite of well proven and reusable inflators and
deflators to complement DBIx::Class.
Added features for these inflators are: - throw an exception if the
serialization doesn't fit in the field - throw an exception if the
deserialization results in an error
Right now there are three serializers: - Storable - JSON - YAML
USAGE
1. Choose your serializer: JSON, YAML or Storable
2. Add 'InflateColumn::Serializer' into the load_components of your
table class
3. add 'serializer_class' => SERIALIZER to the properties of the column
that you want to (de/i)nflate with the SERIALIZER class.
NOTES
As stated in the DBIC FAQ: "Be careful not to overuse this capability,
however. If you find yourself depending more and more on some data
within the inflated column, then it may be time to factor that data
out."
AUTHOR
Jose Luis Martinez
CPAN ID: JLMARTIN
CAPSiDE
jlmartinez@capside.com
http://www.pplusdomain.net
COPYRIGHT
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included
with this module.
THANKS
Matt S Trout for his valuable feedback
Ask Bjorn Hansen
Karen Etheridge
SEE ALSO
DBIx::Class, DBIx::Class::Manual::FAQ
Changes 100644 001750 001750 3246 15171041725 21213 0 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10 Revision history for DBIx-Class-InflateColumn-Serializer
0.10 2026-04-18 22:54:12-04:00 America/New_York
- Update LICENSE file and migrate repo from GitHub to Codeberg.
No functional changes.
0.09 2017-01-14 17:31:18+00:00 Europe/London
- Cosmetic changes to release and test files. No functional changes.
Thanks to paultcochrane for the several PRs
0.08 2016-04-29 22:18:08+01:00 Europe/London
- Tests improved. Ensuring UTF8 encoding works properly. Thanks to kaoru
for the PR
0.07 2014-11-06 20:34:13+00:00 Europe/London
- Switch JSON backend JSON::MaybeXS. Thanks to ether for the PR
0.06 2013-06-28 18:36:02 Europe/Madrid
- Ticket #86304 fixed. Thanks to ribasushi for the bug report :)
0.05 2013-06-03 22:44:09 Europe/Madrid
- Not using GitHub issues for this module
- Version in modules now managed by Dist::Zilla plugin
0.04 2013-05-23 23:02:23 Europe/Madrid
- Some POD errors fixed
- Author tests moved to xt/
- Migrate to Dist::Zilla
0.03 Mon Feb 7 18:48:00 2011
- Migrate to Module::Install
- Declare test_requires and optional packages (solves RT #64925)
- use JSON instead of JSON::Any (RT #61551)
0.02 Sat Jun 27 13:32:00 2009
- Moved from DBIx::Class::Inflator:: to DBIx::Class::InflateColumn
- Moved to a driver model for the serializers. No need to specify
the serializer in the load_components, just InflateColumn::Serializer
- abandonded is_json => 1, is_storable => 1, is_yaml => 1 properties for
serializer_class => 'JSON', serializer_class => 'YAML',
serializer_class => 'Storable'
0.01 Mon Jun 8 22:39:35 2009
- original version
LICENSE 100644 001750 001750 46323 15171041725 20750 0 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10 This software is copyright (c) 2016 by Jose Luis Martinez.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
Terms of the Perl programming language system itself
a) the GNU General Public License as published by the Free
Software Foundation; either version 1, or (at your option) any
later version, or
b) the "Artistic License"
--- The GNU General Public License, Version 1, February 1989 ---
This software is Copyright (c) 2016 by Jose Luis Martinez.
This is free software, licensed under:
The GNU General Public License, Version 1, February 1989
GNU GENERAL PUBLIC LICENSE
Version 1, February 1989
Copyright (C) 1989 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The license agreements of most software companies try to keep users
at the mercy of those companies. By contrast, our General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. The
General Public License applies to the Free Software Foundation's
software and to any other program whose authors commit to using it.
You can use it for your programs, too.
When we speak of free software, we are referring to freedom, not
price. Specifically, the General Public License is designed to make
sure that you have the freedom to give away or sell copies of free
software, that you receive source code or can get it if you want it,
that you can change the software or use pieces of it in new free
programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of a such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must tell them their rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any program or other work which
contains a notice placed by the copyright holder saying it may be
distributed under the terms of this General Public License. The
"Program", below, refers to any such program or work, and a "work based
on the Program" means either the Program or any work containing the
Program or a portion of it, either verbatim or with modifications. Each
licensee is addressed as "you".
1. You may copy and distribute verbatim copies of the Program's source
code as you receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice and
disclaimer of warranty; keep intact all the notices that refer to this
General Public License and to the absence of any warranty; and give any
other recipients of the Program a copy of this General Public License
along with the Program. You may charge a fee for the physical act of
transferring a copy.
2. You may modify your copy or copies of the Program or any portion of
it, and copy and distribute such modifications under the terms of Paragraph
1 above, provided that you also do the following:
a) cause the modified files to carry prominent notices stating that
you changed the files and the date of any change; and
b) cause the whole of any work that you distribute or publish, that
in whole or in part contains the Program or any part thereof, either
with or without modifications, to be licensed at no charge to all
third parties under the terms of this General Public License (except
that you may choose to grant warranty protection to some or all
third parties, at your option).
c) If the modified program normally reads commands interactively when
run, you must cause it, when started running for such interactive use
in the simplest and most usual way, to print or display an
announcement including an appropriate copyright notice and a notice
that there is no warranty (or else, saying that you provide a
warranty) and that users may redistribute the program under these
conditions, and telling the user how to view a copy of this General
Public License.
d) You may charge a fee for the physical act of transferring a
copy, and you may at your option offer warranty protection in
exchange for a fee.
Mere aggregation of another independent work with the Program (or its
derivative) on a volume of a storage or distribution medium does not bring
the other work under the scope of these terms.
3. You may copy and distribute the Program (or a portion or derivative of
it, under Paragraph 2) in object code or executable form under the terms of
Paragraphs 1 and 2 above provided that you also do one of the following:
a) accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of
Paragraphs 1 and 2 above; or,
b) accompany it with a written offer, valid for at least three
years, to give any third party free (except for a nominal charge
for the cost of distribution) a complete machine-readable copy of the
corresponding source code, to be distributed under the terms of
Paragraphs 1 and 2 above; or,
c) accompany it with the information you received as to where the
corresponding source code may be obtained. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form alone.)
Source code for a work means the preferred form of the work for making
modifications to it. For an executable file, complete source code means
all the source code for all modules it contains; but, as a special
exception, it need not include source code for modules which are standard
libraries that accompany the operating system on which the executable
file runs, or for standard header files or definitions files that
accompany that operating system.
4. You may not copy, modify, sublicense, distribute or transfer the
Program except as expressly provided under this General Public License.
Any attempt otherwise to copy, modify, sublicense, distribute or transfer
the Program is void, and will automatically terminate your rights to use
the Program under this License. However, parties who have received
copies, or rights to use copies, from you under this General Public
License will not have their licenses terminated so long as such parties
remain in full compliance.
5. By copying, distributing or modifying the Program (or any work based
on the Program) you indicate your acceptance of this license to do so,
and all its terms and conditions.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the original
licensor to copy, distribute or modify the Program subject to these
terms and conditions. You may not impose any further restrictions on the
recipients' exercise of the rights granted herein.
7. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of the license which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
the license, you may choose any version ever published by the Free Software
Foundation.
8. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to humanity, the best way to achieve this is to make it
free software which everyone can redistribute and change under these
terms.
To do so, attach the following notices to the program. It is safest to
attach them to the start of each source file to most effectively convey
the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
Copyright (C) 19yy
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see .
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19xx name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the
appropriate parts of the General Public License. Of course, the
commands you use may be called something other than `show w' and `show
c'; they could even be mouse-clicks or menu items--whatever suits your
program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
program `Gnomovision' (a program to direct compilers to make passes
at assemblers) written by James Hacker.
, 1 April 1989
Moe Ghoul, President of Vice
That's all there is to it!
--- The Perl Artistic License 1.0 ---
This software is Copyright (c) 2016 by Jose Luis Martinez.
This is free software, licensed under:
The Perl Artistic License 1.0
The "Artistic License"
Preamble
The intent of this document is to state the conditions under which a
Package may be copied, such that the Copyright Holder maintains some
semblance of artistic control over the development of the package,
while giving the users of the package the right to use and distribute
the Package in a more-or-less customary fashion, plus the right to make
reasonable modifications.
Definitions:
"Package" refers to the collection of files distributed by the
Copyright Holder, and derivatives of that collection of files
created through textual modification.
"Standard Version" refers to such a Package if it has not been
modified, or has been modified in accordance with the wishes
of the Copyright Holder as specified below.
"Copyright Holder" is whoever is named in the copyright or
copyrights for the package.
"You" is you, if you're thinking about copying or distributing
this Package.
"Reasonable copying fee" is whatever you can justify on the
basis of media cost, duplication charges, time of people involved,
and so on. (You will not be required to justify it to the
Copyright Holder, but only to the computing community at large
as a market that must bear the fee.)
"Freely Available" means that no fee is charged for the item
itself, though there may be fees involved in handling the item.
It also means that recipients of the item may redistribute it
under the same conditions they received it.
1. You may make and give away verbatim copies of the source form of the
Standard Version of this Package without restriction, provided that you
duplicate all of the original copyright notices and associated disclaimers.
2. You may apply bug fixes, portability fixes and other modifications
derived from the Public Domain or from the Copyright Holder. A Package
modified in such a way shall still be considered the Standard Version.
3. You may otherwise modify your copy of this Package in any way, provided
that you insert a prominent notice in each changed file stating how and
when you changed that file, and provided that you do at least ONE of the
following:
a) place your modifications in the Public Domain or otherwise make them
Freely Available, such as by posting said modifications to Usenet or
an equivalent medium, or placing the modifications on a major archive
site such as uunet.uu.net, or by allowing the Copyright Holder to include
your modifications in the Standard Version of the Package.
b) use the modified Package only within your corporation or organization.
c) rename any non-standard executables so the names do not conflict
with standard executables, which must also be provided, and provide
a separate manual page for each non-standard executable that clearly
documents how it differs from the Standard Version.
d) make other distribution arrangements with the Copyright Holder.
4. You may distribute the programs of this Package in object code or
executable form, provided that you do at least ONE of the following:
a) distribute a Standard Version of the executables and library files,
together with instructions (in the manual page or equivalent) on where
to get the Standard Version.
b) accompany the distribution with the machine-readable source of
the Package with your modifications.
c) give non-standard executables non-standard names, and clearly
document the differences in manual pages (or equivalent), together
with instructions on where to get the Standard Version.
d) make other distribution arrangements with the Copyright Holder.
5. You may charge a reasonable copying fee for any distribution of this
Package. You may charge any fee you choose for support of this
Package. You may not charge a fee for this Package itself. However,
you may distribute this Package in aggregate with other (possibly
commercial) programs as part of a larger (possibly commercial) software
distribution provided that you do not advertise this Package as a
product of your own. You may embed this Package's interpreter within
an executable of yours (by linking); this shall be construed as a mere
form of aggregation, provided that the complete Standard Version of the
interpreter is so embedded.
6. The scripts and library files supplied as input to or produced as
output from the programs of this Package do not automatically fall
under the copyright of this Package, but belong to whoever generated
them, and may be sold commercially, and may be aggregated with this
Package. If such scripts or library files are aggregated with this
Package via the so-called "undump" or "unexec" methods of producing a
binary executable image, then distribution of such an image shall
neither be construed as a distribution of this Package nor shall it
fall under the restrictions of Paragraphs 3 and 4, provided that you do
not represent such an executable image as a Standard Version of this
Package.
7. C subroutines (or comparably compiled subroutines in other
languages) supplied by you and linked into this Package in order to
emulate subroutines and variables of the language defined by this
Package shall not be considered part of this Package, but are the
equivalent of input as in Paragraph 6, provided these subroutines do
not change the language in any way that would cause it to fail the
regression tests for the language.
8. Aggregation of this Package with a commercial distribution is always
permitted provided that the use of this Package is embedded; that is,
when no overt attempt is made to make this Package's interfaces visible
to the end user of the commercial distribution. Such use shall not be
construed as a distribution of this Package.
9. The name of the Copyright Holder may not be used to endorse or promote
products derived from this software without specific prior written permission.
10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
The End
dist.ini 100644 001750 001750 1503 15171041725 21356 0 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10 name = DBIx-Class-InflateColumn-Serializer
author = Jose Luis Martinez (jlmartinez@capside.com)
abstract = Inflators to serialize data structures for DBIx::Class
license = Perl_5
copyright_holder = Jose Luis Martinez
copyright_year = 2016
version = 0.10
[PkgVersion]
[NextRelease]
[ReadmeFromPod]
[CopyReadmeFromBuild]
[MetaProvides::Package]
[MetaJSON]
[MetaResources]
homepage = http://metacpan.org/release/DBIx-Class-InflateColumn-Serializer/
repository = https://codeberg.org/miquelruiz/DBIx-Class-InflateColumn-Serializer.git
[@Git]
allow_dirty = dist.ini
allow_dirty = Changes
allow_dirty = README
[@Filter]
-bundle = @Basic
-remove = Readme
[Prereqs]
perl = 5.8.0
DBIx::Class = 0
JSON::MaybeXS = 1.002005
YAML = 0
namespace::clean = 0
[Prereqs / TestRequires ]
Test::More = 0
Test::Exception = 0
DBD::SQLite = 0
xt 000755 001750 001750 0 15171041725 20206 5 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10 pod.t 100644 001750 001750 255 15171041725 21277 0 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10/xt # -*- perl -*-
use strict;
use warnings;
use Test::More;
eval "use Test::Pod 1.00";
plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
all_pod_files_ok();
META.yml 100644 001750 001750 2647 15171041725 21175 0 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10 ---
abstract: 'Inflators to serialize data structures for DBIx::Class'
author:
- 'Jose Luis Martinez (jlmartinez@capside.com)'
build_requires:
DBD::SQLite: '0'
Test::Exception: '0'
Test::More: '0'
configure_requires:
ExtUtils::MakeMaker: '0'
dynamic_config: 0
generated_by: 'Dist::Zilla version 6.037, CPAN::Meta::Converter version 2.150010'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: '1.4'
name: DBIx-Class-InflateColumn-Serializer
provides:
DBIx::Class::InflateColumn::Serializer:
file: lib/DBIx/Class/InflateColumn/Serializer.pm
version: '0.10'
DBIx::Class::InflateColumn::Serializer::JSON:
file: lib/DBIx/Class/InflateColumn/Serializer/JSON.pm
version: '0.10'
DBIx::Class::InflateColumn::Serializer::Storable:
file: lib/DBIx/Class/InflateColumn/Serializer/Storable.pm
version: '0.10'
DBIx::Class::InflateColumn::Serializer::YAML:
file: lib/DBIx/Class/InflateColumn/Serializer/YAML.pm
version: '0.10'
requires:
DBIx::Class: '0'
JSON::MaybeXS: '1.002005'
YAML: '0'
namespace::clean: '0'
perl: v5.8.0
resources:
homepage: http://metacpan.org/release/DBIx-Class-InflateColumn-Serializer/
repository: https://codeberg.org/miquelruiz/DBIx-Class-InflateColumn-Serializer.git
version: '0.10'
x_generated_by_perl: v5.42.2
x_serialization_backend: 'YAML::Tiny version 1.76'
x_spdx_expression: 'Artistic-1.0-Perl OR GPL-1.0-or-later'
MANIFEST 100644 001750 001750 1224 15171041725 21043 0 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10 # This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.037
Changes
LICENSE
MANIFEST
META.json
META.yml
Makefile.PL
README
TODO
dist.ini
lib/DBIx/Class/InflateColumn/Serializer.pm
lib/DBIx/Class/InflateColumn/Serializer/JSON.pm
lib/DBIx/Class/InflateColumn/Serializer/Storable.pm
lib/DBIx/Class/InflateColumn/Serializer/YAML.pm
t/001_load.t
t/002_storable.t
t/003_json.t
t/004_yaml.t
t/lib/DBICTest.pm
t/lib/DBICTest/Schema.pm
t/lib/DBICTest/Schema/SerializeJSON.pm
t/lib/DBICTest/Schema/SerializeStorable.pm
t/lib/DBICTest/Schema/SerializeYAML.pm
t/lib/DBICTest/Schema/TestTable.pm
t/lib/sqlite.sql
xt/kwalitee.t
xt/pod.t
xt/podcoverage.t
META.json 100644 001750 001750 4105 15171041725 21334 0 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10 {
"abstract" : "Inflators to serialize data structures for DBIx::Class",
"author" : [
"Jose Luis Martinez (jlmartinez@capside.com)"
],
"dynamic_config" : 0,
"generated_by" : "Dist::Zilla version 6.037, CPAN::Meta::Converter version 2.150010",
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : 2
},
"name" : "DBIx-Class-InflateColumn-Serializer",
"prereqs" : {
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"runtime" : {
"requires" : {
"DBIx::Class" : "0",
"JSON::MaybeXS" : "1.002005",
"YAML" : "0",
"namespace::clean" : "0",
"perl" : "v5.8.0"
}
},
"test" : {
"requires" : {
"DBD::SQLite" : "0",
"Test::Exception" : "0",
"Test::More" : "0"
}
}
},
"provides" : {
"DBIx::Class::InflateColumn::Serializer" : {
"file" : "lib/DBIx/Class/InflateColumn/Serializer.pm",
"version" : "0.10"
},
"DBIx::Class::InflateColumn::Serializer::JSON" : {
"file" : "lib/DBIx/Class/InflateColumn/Serializer/JSON.pm",
"version" : "0.10"
},
"DBIx::Class::InflateColumn::Serializer::Storable" : {
"file" : "lib/DBIx/Class/InflateColumn/Serializer/Storable.pm",
"version" : "0.10"
},
"DBIx::Class::InflateColumn::Serializer::YAML" : {
"file" : "lib/DBIx/Class/InflateColumn/Serializer/YAML.pm",
"version" : "0.10"
}
},
"release_status" : "stable",
"resources" : {
"homepage" : "http://metacpan.org/release/DBIx-Class-InflateColumn-Serializer/",
"repository" : {
"url" : "https://codeberg.org/miquelruiz/DBIx-Class-InflateColumn-Serializer.git"
}
},
"version" : "0.10",
"x_generated_by_perl" : "v5.42.2",
"x_serialization_backend" : "Cpanel::JSON::XS version 4.40",
"x_spdx_expression" : "Artistic-1.0-Perl OR GPL-1.0-or-later"
}
Makefile.PL 100644 001750 001750 2541 15171041725 21667 0 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10 # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.037
use strict;
use warnings;
use 5.008000;
use ExtUtils::MakeMaker;
my %WriteMakefileArgs = (
"ABSTRACT" => "Inflators to serialize data structures for DBIx::Class",
"AUTHOR" => "Jose Luis Martinez (jlmartinez\@capside.com)",
"CONFIGURE_REQUIRES" => {
"ExtUtils::MakeMaker" => 0
},
"DISTNAME" => "DBIx-Class-InflateColumn-Serializer",
"LICENSE" => "perl",
"MIN_PERL_VERSION" => "5.008000",
"NAME" => "DBIx::Class::InflateColumn::Serializer",
"PREREQ_PM" => {
"DBIx::Class" => 0,
"JSON::MaybeXS" => "1.002005",
"YAML" => 0,
"namespace::clean" => 0
},
"TEST_REQUIRES" => {
"DBD::SQLite" => 0,
"Test::Exception" => 0,
"Test::More" => 0
},
"VERSION" => "0.10",
"test" => {
"TESTS" => "t/*.t"
}
);
my %FallbackPrereqs = (
"DBD::SQLite" => 0,
"DBIx::Class" => 0,
"JSON::MaybeXS" => "1.002005",
"Test::Exception" => 0,
"Test::More" => 0,
"YAML" => 0,
"namespace::clean" => 0
);
unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) {
delete $WriteMakefileArgs{TEST_REQUIRES};
delete $WriteMakefileArgs{BUILD_REQUIRES};
$WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs;
}
delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
unless eval { ExtUtils::MakeMaker->VERSION(6.52) };
WriteMakefile(%WriteMakefileArgs);
t 000755 001750 001750 0 15171041725 20016 5 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10 001_load.t 100644 001750 001750 505 15171041725 21622 0 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10/t # -*- perl -*-
# t/001_load.t - check module loading and create testing directory
use strict;
use warnings;
use Test::More tests => 1;
BEGIN {
use_ok( 'DBIx::Class::InflateColumn::Serializer' );
}
#my $object = DBIx::Class::Inflator::Serializers->new ();
#isa_ok ($object, 'DBIx::Class::Inflator::Serializers');
004_yaml.t 100644 001750 001750 4624 15171041725 21676 0 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10/t use utf8;
use strict;
use warnings;
use Test::More;
use Test::Exception;
use lib qw(t/lib);
use DBICTest;
my $builder = Test::More->builder;
binmode $builder->output, ":encoding(utf8)";
binmode $builder->failure_output, ":encoding(utf8)";
binmode $builder->todo_output, ":encoding(utf8)";
#eval { require YAML };
#plan( skip_all => 'YAML not installed; skipping' ) if $@;
plan tests => 11;
my $schema = DBICTest->init_schema();
my $struct_hash = {
c => 1,
d => [
{ e => 2 },
],
f => 3,
house => 'château',
heart => "\x{2764}",
};
my $struct_array = [
'c',
{
d => 1,
e => 2
},
'f',
];
my $rs = $schema->resultset("SerializeYAML");
my ($stored, $inflated);
$stored = $rs->create({
'testtable_id' => 3
});
ok($stored->update({ 'serial1' => $struct_hash, 'serial2' => $struct_array }), 'deflation');
my $raw = $schema->storage->dbh_do(sub {
my ($storage, $dbh, @args) = @_;
$dbh->selectrow_hashref('SELECT * from testtable WHERE testtable_id = ?', {}, $stored->testtable_id);
});
like($raw->{serial1}, qr/château/, "raw data contains unicode, as-is, without transformation (latin1-ish 'château')");
like($raw->{serial1}, qr/\x{2764}/, "raw data contains unicode, as-is, without transformation (utf8-ish '\x{2764}')");
#retrieve what was serialized from DB
undef $stored;
$stored = $rs->find({'testtable_id' => 3});
ok($inflated = $stored->serial1, 'hashref inflation');
is_deeply($inflated, $struct_hash, 'the stored hash and the orginial are equal');
ok($inflated = $stored->serial2, 'arrayref inflation');
is_deeply($inflated, $struct_array, 'the stored array and the orginial are equal');
throws_ok(sub {
$stored->update({ 'serial1' => { 'bigkey' => 'm' x 1024 }
});
}, qr/serialization too big/, 'Serialize result bigger than size of column');
ok($stored->update({ 'serial2' => { 'bigkey' => 'm' x 1024 }
})
,'storing a serialization too big for a column without size');
undef $stored;
$stored = $rs->find({'testtable_id' => 3});
TODO: {
local $TODO = 'sqlite doesn\'t truncate TEXT fields...';
throws_ok(sub {
$inflated = $stored->serial2
}, qr/YAML Error/, 'the serialization is truncated, but at least we get an exception');
};
$stored->update({ 'serial1' => undef });
undef $stored;
$stored = $rs->find({'testtable_id' => 3});
ok(not(defined($stored->serial1)), 'serial1 is undefined');
003_json.t 100644 001750 001750 5030 15171041725 21674 0 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10/t use strict;
use warnings;
use utf8;
use Test::More;
use Test::Exception;
use lib qw(t/lib);
use DBICTest;
my $builder = Test::More->builder;
binmode $builder->output, ":encoding(utf8)";
binmode $builder->failure_output, ":encoding(utf8)";
binmode $builder->todo_output, ":encoding(utf8)";
my $schema = DBICTest->init_schema();
plan tests => 13;
my $struct_hash = {
b => 1,
c => [
{ d => 2 },
],
e => 3,
house => 'château',
heart => "\x{2764}",
};
my $struct_array = [
'b',
{
c => 1,
d => 2
},
'e',
];
my $struct_int = 42;
my $rs = $schema->resultset("SerializeJSON");
my ($stored, $inflated);
$stored = $rs->create({
'testtable_id' => 2
});
ok($stored->update({ 'serial1' => $struct_hash, 'serial2' => $struct_array, 'serial3' => $struct_int }), 'deflation');
my $raw = $schema->storage->dbh_do(sub {
my ($storage, $dbh, @args) = @_;
$dbh->selectrow_hashref('SELECT * from testtable WHERE testtable_id = ?', {}, $stored->testtable_id);
});
like($raw->{serial1}, qr/"château"/, "raw data contains unicode, as-is, without transformation (latin1-ish 'château')");
like($raw->{serial1}, qr/"\x{2764}"/, "raw data contains unicode, as-is, without transformation (utf8-ish '\x{2764}')");
#retrieve what was serialized from DB
undef $stored;
$stored = $rs->find({'testtable_id' => 2});
ok($inflated = $stored->serial1, 'hashref inflation');
is_deeply($inflated, $struct_hash, 'the stored hash and the orginial are equal');
ok($inflated = $stored->serial2, 'arrayref inflation');
is_deeply($inflated, $struct_array, 'the stored array and the orginial are equal');
ok($inflated = $stored->serial3, 'int inflation (allowing nonrefs)');
is_deeply($inflated, $struct_int, 'the stored int and the original are equal');
throws_ok(sub {
$stored->update({ 'serial1' => { 'bigkey' => 'n' x 1024 }
});
}, qr/serialization too big/, 'Serialize result bigger than size of column');
ok($stored->update({ 'serial2' => { 'bigkey' => 'n' x 1024 }
})
,'storing a serialization too big for a column without size');
undef $stored;
$stored = $rs->find({'testtable_id' => 2});
TODO: {
local $TODO = 'sqlite doesn\'t truncate TEXT fields...';
throws_ok(sub {
$inflated = $stored->serial2
}, qr/unexpected end of string/, 'the serialization is truncated, but at least we get an exception');
};
$stored->update({ 'serial1' => undef });
undef $stored;
$stored = $rs->find({'testtable_id' => 2});
ok(not(defined($stored->serial1)), 'serial1 is undefined');
kwalitee.t 100644 001750 001750 254 15171041725 22321 0 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10/xt use strict;
use warnings;
use Test::More;
eval { require Test::Kwalitee; Test::Kwalitee->import() };
plan( skip_all => 'Test::Kwalitee not installed; skipping' ) if $@;
002_storable.t 100644 001750 001750 4000 15171041725 22531 0 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10/t use strict;
use warnings;
use Test::More;
use Test::Exception;
use lib qw(t/lib);
use DBICTest;
my $builder = Test::More->builder;
binmode $builder->output, ":encoding(utf8)";
binmode $builder->failure_output, ":encoding(utf8)";
binmode $builder->todo_output, ":encoding(utf8)";
#eval { require Storable };
#plan( skip_all => 'Storable not installed; skipping' ) if $@;
plan tests => 9;
my $schema = DBICTest->init_schema();
my $struct_hash = {
a => 1,
b => [
{ c => 2 },
],
d => 3,
};
my $struct_array = [
'a',
{
b => 1,
c => 2
},
'd',
house => 'château',
heart => "\x{2764}",
];
my $rs = $schema->resultset("SerializeStorable");
my ($stored, $inflated);
$stored = $rs->create({
'testtable_id' => 1
});
ok($stored->update({ 'serial1' => $struct_hash, 'serial2' => $struct_array }), 'deflation');
#retrieve what was serialized from DB
undef $stored;
$stored = $rs->find({'testtable_id' => 1});
ok($inflated = $stored->serial1, 'hashref inflation');
is_deeply($inflated, $struct_hash, 'the stored hash and the orginial are equal');
ok($inflated = $stored->serial2, 'arrayref inflation');
is_deeply($inflated, $struct_array, 'the stored array and the orginial are equal');
throws_ok(sub {
$stored->update({ 'serial1' => { 'bigkey' => '-' x 1024 }
});
}, qr/serialization too big/, 'Serialize result bigger than size of column');
ok($stored->update({ 'serial2' => { 'bigkey' => '-' x 1024 }
})
,'storing a serialization too big for a column without size');
undef $stored;
$stored = $rs->find({'testtable_id' => 1});
TODO: {
local $TODO = 'sqlite doesn\'t truncate TEXT fields...';
throws_ok(sub {
$inflated = $stored->serial2
}, qr/Storable couldn't thaw the value/, 'the serialization is truncated, but at least we get an exception');
};
$stored->update({ 'serial1' => undef });
undef $stored;
$stored = $rs->find({'testtable_id' => 1});
ok(not(defined($stored->serial1)), 'serial1 is undefined');
lib 000755 001750 001750 0 15171041725 20564 5 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10/t sqlite.sql 100644 001750 001750 220 15171041725 22720 0 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10/t/lib CREATE TABLE testtable (
testtable_id INTEGER PRIMARY KEY NOT NULL,
serial1 VARCHAR(100),
serial2 VARCHAR(100),
serial3 VARCHAR(10)
);
podcoverage.t 100644 001750 001750 653 15171041725 23015 0 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10/xt # -*- perl -*-
use strict;
use warnings;
use Test::More;
eval "use Test::Pod::Coverage 1.00";
plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD coverage" if $@;
plan tests => 3;
pod_coverage_ok(
'DBIx::Class::InflateColumn::Serializer::Storable',
);
pod_coverage_ok(
'DBIx::Class::InflateColumn::Serializer::JSON',
);
pod_coverage_ok(
'DBIx::Class::InflateColumn::Serializer::YAML',
);
DBICTest.pm 100644 001750 001750 4735 15171041725 22634 0 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10/t/lib package # hide from PAUSE
DBICTest;
use strict;
use warnings;
use DBICTest::Schema;
sub populate_schema {
}
sub has_custom_dsn {
return $ENV{"DBICTEST_DSN"} ? 1:0;
}
sub _sqlite_dbfilename {
return "t/var/DBIxClass.db";
}
sub _sqlite_dbname {
my $self = shift;
my %args = @_;
return $self->_sqlite_dbfilename if $args{sqlite_use_file} or $ENV{"DBICTEST_SQLITE_USE_FILE"};
return ":memory:";
}
sub _database {
my $self = shift;
my %args = @_;
my $db_file = $self->_sqlite_dbname(%args);
unlink($db_file) if -e $db_file;
unlink($db_file . "-journal") if -e $db_file . "-journal";
mkdir("t/var") unless -d "t/var";
my $dsn = $ENV{"DBICTEST_DSN"} || "dbi:SQLite:${db_file}";
my $dbuser = $ENV{"DBICTEST_DBUSER"} || '';
my $dbpass = $ENV{"DBICTEST_DBPASS"} || '';
my @connect_info = ($dsn, $dbuser, $dbpass, { AutoCommit => 1, sqlite_unicode => 1, %args });
return @connect_info;
}
sub init_schema {
my $self = shift;
my %args = @_;
my $schema;
$args{'no_deploy'} = $ENV{'DBICTEST_NODEPLOY'} if (defined $ENV{'DBICTEST_NODEPLOY'});
if ($args{compose_connection}) {
$schema = DBICTest::Schema->compose_connection(
'DBICTest', $self->_database(%args)
);
} else {
$schema = DBICTest::Schema->compose_namespace('DBICTest');
}
if( $args{storage_type}) {
$schema->storage_type($args{storage_type});
}
if ( !$args{no_connect} ) {
$schema = $schema->connect($self->_database(%args));
$schema->storage->on_connect_do(['PRAGMA synchronous = OFF'])
unless $self->has_custom_dsn;
}
if ( !$args{no_deploy} ) {
__PACKAGE__->deploy_schema( $schema, $args{deploy_args} );
__PACKAGE__->populate_schema( $schema )
if( !$args{no_populate} );
}
return $schema;
}
sub deploy_schema {
my $self = shift;
my $schema = shift;
my $args = shift || {};
if ($ENV{"DBICTEST_SQLT_DEPLOY"}) {
$schema->deploy($args);
} else {
open my $input, "<", "t/lib/sqlite.sql";
my $sql;
{ local $/ = undef; $sql = <$input>; }
close $input;
for my $chunk ( split (/;\s*\n+/, $sql) ) {
if ( $chunk =~ / ^ (?! --\s* ) \S /xm ) { # there is some real sql in the chunk - a non-space at the start of the string which is not a comment
$schema->storage->dbh->do($chunk) or print "Error on SQL: $chunk\n";
}
}
}
return;
}
1;
1;
DBICTest 000755 001750 001750 0 15171041725 22125 5 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10/t/lib Schema.pm 100644 001750 001750 340 15171041725 24000 0 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10/t/lib/DBICTest package # hide from PAUSE
DBICTest::Schema;
use strict;
use warnings;
use base qw/DBIx::Class::Schema/;
no warnings qw/qw/;
__PACKAGE__->load_classes(qw/
SerializeStorable
SerializeJSON
SerializeYAML
/);
1;
Schema 000755 001750 001750 0 15171041725 23325 5 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10/t/lib/DBICTest TestTable.pm 100644 001750 001750 744 15171041725 25677 0 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10/t/lib/DBICTest/Schema package # hide from PAUSE
DBICTest::Schema::TestTable;
use strict;
use warnings;
use base qw/DBIx::Class/;
__PACKAGE__->load_components (qw/Core/);
__PACKAGE__->table('testtable');
__PACKAGE__->add_columns(
'testtable_id' => {
data_type => 'integer',
},
'serial1' => {
data_type => 'varchar',
size => 100,
is_nullable => 1,
},
'serial2' => {
data_type => 'varchar'
is_nullable => 1,
}
);
__PACKAGE__->set_primary_key('testtable_id');
1;
SerializeJSON.pm 100644 001750 001750 1334 15171041725 26445 0 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10/t/lib/DBICTest/Schema package # hide from PAUSE
DBICTest::Schema::SerializeJSON;
use strict;
use warnings;
use base qw/DBIx::Class/;
__PACKAGE__->load_components (qw/InflateColumn::Serializer Core/);
__PACKAGE__->table('testtable');
__PACKAGE__->add_columns(
'testtable_id' => {
data_type => 'integer',
},
'serial1' => {
data_type => 'varchar',
size => 100,
serializer_class => 'JSON',
is_nullable => 1,
},
'serial2' => {
data_type => 'varchar',
serializer_class => 'JSON',
is_nullable => 1,
},
'serial3' => {
data_type => 'varchar',
serializer_class => 'JSON',
serializer_options => { allow_nonref => 1 },
is_nullable => 1,
}
);
__PACKAGE__->set_primary_key('testtable_id');
1;
SerializeYAML.pm 100644 001750 001750 1103 15171041725 26430 0 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10/t/lib/DBICTest/Schema package # hide from PAUSE
DBICTest::Schema::SerializeYAML;
use strict;
use warnings;
use base qw/DBIx::Class/;
__PACKAGE__->load_components (qw/InflateColumn::Serializer Core/);
__PACKAGE__->table('testtable');
__PACKAGE__->add_columns(
'testtable_id' => {
data_type => 'integer',
},
'serial1' => {
data_type => 'varchar',
size => 100,
serializer_class => 'YAML',
is_nullable => 1,
},
'serial2' => {
data_type => 'varchar',
serializer_class => 'YAML',
is_nullable => 1,
}
);
__PACKAGE__->set_primary_key('testtable_id');
1;
InflateColumn 000755 001750 001750 0 15171041725 24714 5 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10/lib/DBIx/Class Serializer.pm 100644 001750 001750 6550 15171041725 27531 0 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10/lib/DBIx/Class/InflateColumn package DBIx::Class::InflateColumn::Serializer;
$DBIx::Class::InflateColumn::Serializer::VERSION = '0.10';
use strict;
use warnings;
sub register_column {
my $self = shift;
my ($column, $info, $args) = @_;
$self->next::method(@_);
return unless defined $info->{'serializer_class'};
my $class = "DBIx::Class::InflateColumn::Serializer::$info->{'serializer_class'}";
eval "require ${class};";
$self->throw_exception("Failed to use serializer_class '${class}': $@") if $@;
defined( my $freezer = eval{ $class->get_freezer($column, $info, $args) }) ||
$self->throw_exception("Failed to create freezer with class '$class': $@");
defined( my $unfreezer = eval{ $class->get_unfreezer($column, $info, $args) }) ||
$self->throw_exception("Failed to create unfreezer with class '$class': $@");
$self->inflate_column(
$column => {
inflate => $unfreezer,
deflate => $freezer,
}
);
};
=head1 NAME
DBIx::Class::InflateColumn::Serializer - Inflators to serialize data structures for DBIx::Class
=head1 SYNOPSIS
package MySchema::Table;
use base 'DBIx::Class';
__PACKAGE__->load_components('InflateColumn::Serializer', 'Core');
__PACKAGE__->add_columns(
'data_column' => {
'data_type' => 'VARCHAR',
'size' => 255,
'serializer_class' => 'JSON'
}
);
Then in your code...
my $struct = { 'I' => { 'am' => 'a struct' };
$obj->data_column($struct);
$obj->update;
And you can recover your data structure with:
my $obj = ...->find(...);
my $struct = $obj->data_column;
The data structures you assign to "data_column" will be saved in the database in JSON format.
=head1 DESCRIPTION
These modules help you store and access serialized data structures in the columns of your DB from your DBIx::Classes. They are inspired from the DBIx::Class::Manual::FAQ and the DBIC test suite, and provide a bit more protection than the inflators proposed in the FAQ. The intention is to provide a suite of well proven and reusable inflators and deflators to complement DBIx::Class.
Added features for these inflators are:
- throw an exception if the serialization doesn't fit in the field
- throw an exception if the deserialization results in an error
Right now there are three serializers:
- Storable
- JSON
- YAML
=head1 USAGE
1. Choose your serializer: JSON, YAML or Storable
2. Add 'InflateColumn::Serializer' into the load_components of your table class
3. add 'serializer_class' => SERIALIZER to the properties of the column that you want to (de/i)nflate
with the SERIALIZER class.
=head1 NOTES
As stated in the DBIC FAQ: "Be careful not to overuse this capability, however. If you find yourself depending more and more on some data within the inflated column, then it may be time to factor that data out."
=head1 AUTHOR
Jose Luis Martinez
CPAN ID: JLMARTIN
CAPSiDE
jlmartinez@capside.com
http://www.pplusdomain.net
=head1 COPYRIGHT
This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the
LICENSE file included with this module.
=head1 THANKS
Matt S Trout for his valuable feedback
Ask Bjorn Hansen
Karen Etheridge
=head1 SEE ALSO
DBIx::Class, DBIx::Class::Manual::FAQ
=cut
#################### main pod documentation end ###################
1;
SerializeStorable.pm 100644 001750 001750 1117 15171041725 27446 0 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10/t/lib/DBICTest/Schema package # hide from PAUSE
DBICTest::Schema::SerializeStorable;
use strict;
use warnings;
use base qw/DBIx::Class/;
__PACKAGE__->load_components (qw/InflateColumn::Serializer Core/);
__PACKAGE__->table('testtable');
__PACKAGE__->add_columns(
'testtable_id' => {
data_type => 'integer',
},
'serial1' => {
data_type => 'varchar',
size => 100,
serializer_class => 'Storable',
is_nullable => 1,
},
'serial2' => {
data_type => 'varchar',
serializer_class => 'Storable',
is_nullable => 1,
}
);
__PACKAGE__->set_primary_key('testtable_id');
1;
Serializer 000755 001750 001750 0 15171041725 27025 5 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10/lib/DBIx/Class/InflateColumn YAML.pm 100644 001750 001750 3134 15171041725 30266 0 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10/lib/DBIx/Class/InflateColumn/Serializer package DBIx::Class::InflateColumn::Serializer::YAML;
$DBIx::Class::InflateColumn::Serializer::YAML::VERSION = '0.10';
=head1 NAME
DBIx::Class::InflateColumn::Serializer::YAML - YAML Inflator
=head1 SYNOPSIS
package MySchema::Table;
use base 'DBIx::Class';
__PACKAGE__->load_components('InflateColumn::Serializer', 'Core');
__PACKAGE__->add_columns(
'data_column' => {
'data_type' => 'VARCHAR',
'size' => 255,
'serializer_class' => 'YAML'
}
);
Then in your code...
my $struct = { 'I' => { 'am' => 'a struct' };
$obj->data_column($struct);
$obj->update;
And you can recover your data structure with:
my $obj = ...->find(...);
my $struct = $obj->data_column;
The data structures you assign to "data_column" will be saved in the database in YAML format.
=cut
use strict;
use warnings;
use YAML;
use Carp;
=over 4
=item get_freezer
Called by DBIx::Class::InflateColumn::Serializer to get the routine that serializes
the data passed to it. Returns a coderef.
=cut
sub get_freezer{
my ($class, $column, $info, $args) = @_;
if (defined $info->{'size'}){
my $size = $info->{'size'};
return sub {
my $s = YAML::Dump(shift);
croak "serialization too big" if (length($s) > $size);
return $s;
};
} else {
return sub {
return YAML::Dump(shift);
};
}
}
=item get_unfreezer
Called by DBIx::Class::InflateColumn::Serializer to get the routine that deserializes
the data stored in the column. Returns a coderef.
=back
=cut
sub get_unfreezer {
return sub {
return YAML::Load(shift);
};
}
1;
JSON.pm 100644 001750 001750 4221 15171041725 30273 0 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10/lib/DBIx/Class/InflateColumn/Serializer package DBIx::Class::InflateColumn::Serializer::JSON;
$DBIx::Class::InflateColumn::Serializer::JSON::VERSION = '0.10';
=head1 NAME
DBIx::Class::InflateColumn::Serializer::JSON - JSON Inflator
=head1 SYNOPSIS
package MySchema::Table;
use base 'DBIx::Class';
__PACKAGE__->load_components('InflateColumn::Serializer', 'Core');
__PACKAGE__->add_columns(
'data_column' => {
'data_type' => 'VARCHAR',
'size' => 255,
'serializer_class' => 'JSON',
'serializer_options' => { allow_blessed => 1, convert_blessed => 1, pretty => 1 }, # optional
}
);
Then in your code...
my $struct = { 'I' => { 'am' => 'a struct' };
$obj->data_column($struct);
$obj->update;
And you can recover your data structure with:
my $obj = ...->find(...);
my $struct = $obj->data_column;
The data structures you assign to "data_column" will be saved in the database in JSON format.
Any arguments included in C will be passed to the L constructor,
to be used by the JSON backend for both serializing and deserializing.
=cut
use strict;
use warnings;
use JSON::MaybeXS;
use Carp;
use namespace::clean;
=over 4
=item get_freezer
Called by DBIx::Class::InflateColumn::Serializer to get the routine that serializes
the data passed to it. Returns a coderef.
=cut
sub get_freezer{
my ($class, $column, $info, $args) = @_;
my $opts = $info->{serializer_options};
my $serializer = JSON::MaybeXS->new($opts && %$opts ? %$opts: ());
if (defined $info->{'size'}){
my $size = $info->{'size'};
return sub {
my $s = $serializer->encode(shift);
croak "serialization too big" if (length($s) > $size);
return $s;
};
} else {
return sub {
return $serializer->encode(shift);
};
}
}
=item get_unfreezer
Called by DBIx::Class::InflateColumn::Serializer to get the routine that deserializes
the data stored in the column. Returns a coderef.
=back
=cut
sub get_unfreezer {
my ($class, $column, $info, $args) = @_;
my $opts = $info->{serializer_options};
return sub {
JSON::MaybeXS->new($opts && %$opts ? %$opts : ())->decode(shift);
};
}
1;
Storable.pm 100644 001750 001750 3770 15171041725 31305 0 ustar 00mruiz mruiz 000000 000000 DBIx-Class-InflateColumn-Serializer-0.10/lib/DBIx/Class/InflateColumn/Serializer package DBIx::Class::InflateColumn::Serializer::Storable;
$DBIx::Class::InflateColumn::Serializer::Storable::VERSION = '0.10';
=head1 NAME
DBIx::Class::InflateColumn::Serializer::Storable - Storable Inflator
=head1 SYNOPSIS
package MySchema::Table;
use base 'DBIx::Class';
__PACKAGE__->load_components('InflateColumn::Serializer', 'Core');
__PACKAGE__->add_columns(
'data_column' => {
'data_type' => 'VARCHAR',
'size' => 255,
'serializer_class' => 'Storable'
}
);
Then in your code...
my $struct = { 'I' => { 'am' => 'a struct' };
$obj->data_column($struct);
$obj->update;
And you can recover your data structure with:
my $obj = ...->find(...);
my $struct = $obj->data_column;
The data structures you assign to "data_column" will be saved in the database in Storable format.
=cut
use strict;
use warnings;
use Storable qw//;
use Carp;
=over 4
=item get_freezer
Called by DBIx::Class::InflateColumn::Serializer to get the routine that serializes
the data passed to it. Returns a coderef.
=cut
sub get_freezer{
my ($class, $column, $info, $args) = @_;
if (defined $info->{'size'}){
my $size = $info->{'size'};
return sub {
my $s = Storable::nfreeze(shift);
croak "serialization too big" if (length($s) > $size);
return $s;
};
} else {
return sub {
return Storable::nfreeze(shift);
};
}
}
=item get_unfreezer
Called by DBIx::Class::InflateColumn::Serializer to get the routine that deserializes
the data stored in the column. Returns a coderef.
=back
=cut
sub get_unfreezer {
return sub {
my $value = shift;
# Storable returns undef if the datastructure couldn't be thawed.
# Other deserializers throw exceptions, so we'll do the same.
# If the column had a NULL value, then we return it (don't want to die)
return undef if (not defined $value);
my $s = Storable::thaw($value);
croak "Storable couldn't thaw the value" if (not defined $s);
return $s;
};
}
1;