use Carp qw/croak/;
use XSLoader;
-our $VERSION = '4.004'; # Don't forget to update the TestCompat set for testing against installed decoders!
+our $VERSION = '4.005'; # Don't forget to update the TestCompat set for testing against installed decoders!
our $XS_VERSION = $VERSION; $VERSION= eval $VERSION;
# not for public consumption, just for testing.
sub encode_to_file {
my ($self, $file, $struct, $append)= @_;
+ $self= $self->new() unless ref $self;
my $mode= $append ? ">>" : ">";
open my $fh, $mode, $file
or die "Failed to open '$file' for " . ($append ? "append" : "write") . ": $!";
information, in a document that allows users to avoid deserializing main body
needlessly.
+=head2 encode_to_file
+
+ Sereal::Decoder->encode_to_file($file,$data,$append);
+ $encoder->encode_to_file($file,$data,$append);
+
+Encode the data specified and write it the named file.
+If $append is true then the written data is appended to any
+existing data, otherwise any existing data will be overwritten.
+Dies if any errors occur during writing the encoded data.
+
=head1 EXPORTABLE FUNCTIONS
=head2 sereal_encode_with_object
sub have_encoder_and_decoder {
my ($min_v)= @_;
# $Class is the already-loaded class, so the one we're testing
- my $need = $Class =~ /Encoder/ ? "Decoder" : "Encoder";
- my $need_class = "Sereal::$need";
-
- eval "use $Class; 1"
- or do {
- note("Could not locate $Class for testing" . ($@ ? " (Exception: $@)" : ""));
- return();
- };
+ my @need = $Class =~ /Encoder/ ? ("Decoder") :
+ $Class =~ /Decoder/ ? ("Encoder") :
+ ("Encoder", "Decoder");
+ my @need_class = ($Class, map { "Sereal::$_" } @need);
+
+ foreach my $class (@need_class) {
+ eval "use $class; 1"
+ or do {
+ note("Could not locate $class for testing" . ($@ ? " (Exception: $@)" : ""));
+ return();
+ };
+ my $cmp_v= $class->VERSION;
+
+ if ($min_v and $cmp_v < $min_v) {
+ diag("Could not load correct version of $class for testing "
+ ."(got: $cmp_v, needed at least $min_v)");
+ return;
+ }
- eval "use $need_class; 1"
- or do {
- note("Could not locate $need_class for testing" . ($@ ? " (Exception: $@)" : ""));
- return();
- };
- my $cmp_v = $need_class->VERSION;
- if ($min_v and $cmp_v < $min_v) {
- diag("Could not load correct version of $need_class for testing "
- ."(got: $cmp_v, needed at least $min_v)");
- return;
- }
- $cmp_v =~ s/_//;
- $cmp_v = sprintf("%.2f", int($cmp_v*100)/100);
- my %compat_versions = map {$_ => 1} $Class->_test_compat();
- if (not defined $cmp_v or not exists $compat_versions{$cmp_v}) {
- diag("Could not load correct version of $need_class for testing "
- ."(got: $cmp_v, needed any of ".join(", ", keys %compat_versions).")");
- return();
+ $cmp_v =~ s/_//;
+ $cmp_v = sprintf("%.2f", int($cmp_v*100)/100);
+ my %compat_versions = map {$_ => 1} $Class->_test_compat();
+ if (not defined $cmp_v or not exists $compat_versions{$cmp_v}) {
+ diag("Could not load correct version of $class for testing "
+ ."(got: $cmp_v, needed any of ".join(", ", keys %compat_versions).")");
+ return();
+ }
}
+
return 1;
}