I have a mood class that I would like to use the Apache :: Session :: file.
However, the Apache :: Session :: file will not store it by default and in return I get an error message:
(to clean) Blob \ lib Can not store CODE items on \ Storable .pm (autosplit in blib \ lib \ aut \ Storable \ _freeze.al) ...
This problem can be stopped by setting < / P>
$ storable :: Deparse = 1; $ Storable :: Eval = 1;
To allow CODE references to be serialized.
The abusive method in the mood class is listed below, which receives one column from a mysql database:
sub_build_cell_generic {my ($ self, $ col)) = @_; My $ sth = $ self- & gt; Call_dbh ('ready', 'select'. $ Col. 'to' $ self- & gt; table. 'Where CI =? And LAC =? And IMPORTDATE =?'); $ Sth- & gt; But execute ($ self & gt; CI, $ self & gt; LAC, $ self-IMPORTDATE); My $ val = $ sth- & gt; Fetchrow_array; $ Sth- & gt; Finish; Return define $ val? $ Val: undef; }
Therefore, possibly the code reference in the DB object (ISI dBIX :: connector) is included.
Is there a better option for allowing the serialization of this Muz square class $ Storable :: Deparse and $ Storable :: Eval Settings
The following test script generates error:
#! / Usr / bin / perl -w uses Apache :: Session :: File; Test :: Use more; Strict use; Use warnings; Need_ok ('GSM :: TestCell'); Need_ok ('GSM :: SQL Connection'); My $ db = new_ok ('GSM :: SQL Connection'); My $ cell4 = new_ok ('GSM :: testseal' => [[LAC => 406, CI = 24491, dB => $ db}]); My% session; Tie% Session, 'Apache :: Session :: File', End, {directory = & gt; "./", lock directory = & gt; "./"}; Print is "BCCH", $ cell 4- & gt; BCCH, "\ n"; $ Session {$ cell 4- & gt; Id} = $ cell 4; Done_testing (); ___END__
The SQL Connection class is defined as:
package GSM :: SQL connection; #Usage DBI; Use mousse; Use the DBIKS :: connector; Is dbixc = & gt; (= Is> & gt; 'ro', isa = & gt; 'dbiex :: connector', alia_build => 1, handle = & gt; [qw (dbh)]; Sub_build_dbixc {my $ self = shift; My $ DSN = 'DBI: MyScall: TestDB; Host = 127.0.0.1; Port = 3306 '; Return DBiX :: Connector-> New ($ DSN, 'User', 'PWD'); } Sub call_dbh {my $ self = shift; My $ method = shift; My @args = @_; $ Self- gt; Dbixc- & gt; Run (fixup = & gt; sub {$ _- & gt; $ method (@args)}); } No Moose; __PACKAGE __- & gt; Meta & gt; Make_immutable; 1;
Test class class is defined:
package GSM :: TestCell; MooseX :: Use natural; Strict use; Use warnings; [Qw (LAC CI)] = & gt; (Is => 'ro', required => 1); Is [qw (id bcch ipo)] => (Is = & gt; 'rw', lazy_build = & gt; 1); 'Db' = & gt; (= = => 'RW', ISA = & gt; 'GSM :: SQL connection', required => 1,); 'Tab' = & gt; (Is => 'rw', default = & gt; 'cell'); Primary key = & gt; ('LAC', 'CI'); Sub_build_id {My $ self = shift; Join the return (',', $ self-> LAC, $ self-> CI); } Sub_build_IMPORTDATE {returns '2010-06-21'} sub_build_becc {(shift) -> _build_cell_generic ('BCCFFQC');} sub_build_ cell_generic {my ($ self, $ col)) = @_; My $ sth = $ self- & gt; DB- & gt; Call_dbh ('ready', 'select'. $ Col. 'to' $ self- & gt; table. 'Where CI =? And LAC =? And IMPORTDATE =?'); $ Sth- & gt; But execute ($ self & gt; CI, $ self & gt; LAC, $ self-IMPORTDATE); My $ val = $ sth- & gt; Fetchrow_array; $ Sth- & gt; Finish; Return define $ val? $ Val: undef; } No Moose; __PACKAGE __- & gt; Meta & gt; Make_immutable; 1;
I really doubt that you need to sort code references; None of the examples you have included do not want to serialize the DBIKS :: connector objects, because they are specific to the existing runtime instances only.
In DBiX :: connector objects they may have a small codec, because it is common
The serialization of the mousse object is controlled, which easily grows. To satisfy your needs, you can customize a serializer - that's what features and who want to ignore the serialization.
Comments
Post a Comment