Skip to content

Commit f067446

Browse files
committed
more progress on perl wrapper
use MooseX::Clone role remove DESTROY function from XDIFile (may need to revisit...)
1 parent ea264b9 commit f067446

File tree

3 files changed

+56
-47
lines changed

3 files changed

+56
-47
lines changed

perl/Makefile.PL

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ WriteMakefile(
2727
Moose => 2.06,
2828
'MooseX::NonMoose' => 0.22,
2929
'MooseX::Aliases' => 0.10,
30+
'MooseX::Clone' => 0.05,
3031
},
3132
($] >= 5.005 ? ## Add these new keywords supported since 5.005
3233
(ABSTRACT_FROM => 'lib/Xray/XDI.pm', # retrieve abstract from module

perl/lib/Xray/XDI.pm

Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,47 @@ use MooseX::NonMoose;
55
use MooseX::Aliases;
66
extends 'Xray::XDIFile';
77
with 'Xray::XDI::WriterPP';
8+
with 'MooseX::Clone';
89

910
use List::MoreUtils qw(any uniq);
1011

1112
our $VERSION = '1.00'; # Inline::MakeMake uses /^\d.\d\d$/ as the pattern for the version number -- note the two digits to the right of the dot
1213

13-
has 'file' => (is => 'rw', isa => 'Str', default => q{},
14+
has 'file' => (is => 'rw', isa => 'Str', traits => [qw(Clone)], default => q{},
1415
trigger => sub{$_[0]->_build_object});
1516

1617
has 'xdifile' => (
1718
is => 'ro',
19+
traits => [qw(NoClone)],
1820
isa => 'Xray::XDIFile',
1921
init_arg => undef,
2022
lazy => 1,
2123
builder => '_build_object',
2224
);
2325
# no need to fiddle with inline_constructor here
24-
has 'ok' => (is => 'rw', isa => 'Bool', default => 0);
25-
has 'warning' => (is => 'rw', isa => 'Bool', default => 0);
26-
has 'errorcode' => (is => 'rw', isa => 'Int', default => 0);
27-
has 'error' => (is => 'rw', isa => 'Str', default => q{});
28-
29-
has 'filename' => (is => 'rw', isa => 'Str', default => q{});
30-
has 'xdi_libversion' => (is => 'rw', isa => 'Str', default => q{});
31-
has 'xdi_version' => (is => 'rw', isa => 'Str', default => q{});
32-
has 'extra_version' => (is => 'rw', isa => 'Str', default => q{});
33-
has 'element' => (is => 'rw', isa => 'Str', default => q{});
34-
has 'edge' => (is => 'rw', isa => 'Str', default => q{});
35-
has 'dspacing' => (is => 'rw', isa => 'Num', default => 0);
36-
has 'comments' => (is => 'rw', isa => 'Str', default => q{});
37-
has 'nmetadata' => (is => 'rw', isa => 'Int', default => 0);
38-
has 'npts' => (is => 'rw', isa => 'Int', default => 0);
39-
has 'narrays' => (is => 'rw', isa => 'Int', default => 0);
40-
has 'narray_labels' => (is => 'rw', isa => 'Int', default => 0);
41-
42-
has 'array_labels' => (is => 'rw', isa => 'ArrayRef', default => sub{[]});
43-
has 'array_units' => (is => 'rw', isa => 'ArrayRef', default => sub{[]});
26+
has 'ok' => (is => 'rw', isa => 'Bool', traits => [qw(NoClone)], default => 0);
27+
has 'warning' => (is => 'rw', isa => 'Bool', traits => [qw(NoClone)], default => 0);
28+
has 'errorcode' => (is => 'rw', isa => 'Int', traits => [qw(NoClone)], default => 0);
29+
has 'error' => (is => 'rw', isa => 'Str', traits => [qw(NoClone)], default => q{});
30+
31+
has 'filename' => (is => 'rw', isa => 'Str', traits => [qw(NoClone)], default => q{});
32+
has 'xdi_libversion' => (is => 'rw', isa => 'Str', traits => [qw(Clone)], default => q{});
33+
has 'xdi_version' => (is => 'rw', isa => 'Str', traits => [qw(Clone)], default => q{});
34+
has 'extra_version' => (is => 'rw', isa => 'Str', traits => [qw(Clone)], default => q{});
35+
has 'element' => (is => 'rw', isa => 'Str', traits => [qw(Clone)], default => q{});
36+
has 'edge' => (is => 'rw', isa => 'Str', traits => [qw(Clone)], default => q{});
37+
has 'dspacing' => (is => 'rw', isa => 'Num', traits => [qw(Clone)], default => 0);
38+
has 'comments' => (is => 'rw', isa => 'Str', traits => [qw(Clone)], default => q{});
39+
has 'nmetadata' => (is => 'rw', isa => 'Int', traits => [qw(Clone)], default => 0);
40+
has 'npts' => (is => 'rw', isa => 'Int', traits => [qw(Clone)], default => 0);
41+
has 'narrays' => (is => 'rw', isa => 'Int', traits => [qw(Clone)], default => 0);
42+
has 'narray_labels' => (is => 'rw', isa => 'Int', traits => [qw(Clone)], default => 0);
43+
44+
has 'array_labels' => (is => 'rw', isa => 'ArrayRef', traits => [qw(Clone)], default => sub{[]});
45+
has 'array_units' => (is => 'rw', isa => 'ArrayRef', traits => [qw(Clone)], default => sub{[]});
4446

4547
has 'metadata' => (
46-
traits => ['Hash'],
48+
traits => ['Hash', 'Clone'],
4749
is => 'rw',
4850
isa => 'HashRef',
4951
default => sub { {} },
@@ -55,18 +57,18 @@ has 'metadata' => (
5557
},
5658
);
5759

58-
has 'data' => (
59-
traits => ['Hash'],
60-
is => 'rw',
61-
isa => 'HashRef',
62-
default => sub { {} },
63-
handles => {
64-
'exists_in_data' => 'exists',
65-
'ids_in_data' => 'keys',
66-
'get_data' => 'get',
67-
'set_data' => 'set',
68-
},
69-
);
60+
has 'data' => (
61+
traits => ['Hash', 'NoClone'],
62+
is => 'rw',
63+
isa => 'HashRef',
64+
default => sub { {} },
65+
handles => {
66+
'exists_in_data' => 'exists',
67+
'ids_in_data' => 'keys',
68+
'get_data' => 'get',
69+
'set_data' => 'set',
70+
},
71+
);
7072

7173
sub _build_object {
7274
my ($self) = @_;
@@ -232,6 +234,14 @@ sub set_item {
232234
return $self;
233235
};
234236

237+
sub delete_item {
238+
my ($self, $family, $keyword) = @_;
239+
my $rhash = $self->metadata;
240+
delete $rhash->{$family}->{$keyword};
241+
$self->metadata($rhash);
242+
return $self;
243+
};
244+
235245
sub push_comment {
236246
my ($self, @comments) = @_;
237247
my $all = $self->comments;
@@ -269,6 +279,17 @@ sub token {
269279
};
270280

271281

282+
sub serialize {
283+
my ($self) = @_;
284+
my $copy = $self->clone;
285+
$copy->data({});
286+
local $Data::Dumper::Indent = 0;
287+
my $string = $copy->dump(3);
288+
undef $copy;
289+
return $string;
290+
};
291+
292+
272293
no Moose;
273294
__PACKAGE__->meta->make_immutable;
274295
1;

perl/lib/Xray/XDIFile.pm

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -321,16 +321,3 @@ void _data_array(SV* obj, long col) {
321321
}
322322
323323
324-
void DESTROY(SV* obj) {
325-
XDIFile* xdifile = INT2PTR(XDIFile*, SvIV(SvRV(obj)));
326-
Safefree(xdifile->xdi_libversion);
327-
Safefree(xdifile->xdi_version);
328-
Safefree(xdifile->extra_version);
329-
Safefree(xdifile->filename);
330-
Safefree(xdifile->element);
331-
Safefree(xdifile->edge);
332-
Safefree(xdifile->comments);
333-
Safefree(xdifile->error_line);
334-
Safefree(xdifile->outer_label);
335-
Safefree(xdifile);
336-
}

0 commit comments

Comments
 (0)