@@ -25,10 +25,7 @@ has 'xdifile' => (
25
25
builder => ' _build_object' ,
26
26
);
27
27
# no need to fiddle with inline_constructor here
28
- has ' ok' => (is => ' rw' , isa => ' Bool' , traits => [qw( NoClone) ], default => 0);
29
- has ' warning' => (is => ' rw' , isa => ' Bool' , traits => [qw( NoClone) ], default => 0);
30
28
has ' errorcode' => (is => ' rw' , isa => ' Int' , traits => [qw( NoClone) ], default => 0);
31
- has ' error' => (is => ' rw' , isa => ' Str' , traits => [qw( NoClone) ], default => q{ } );
32
29
has ' errormessage' => (is => ' rw' , isa => ' Str' , traits => [qw( NoClone) ], default => q{ } );
33
30
34
31
has ' filename' => (is => ' rw' , isa => ' Str' , traits => [qw( NoClone) ], default => q{ } );
@@ -83,30 +80,24 @@ sub DEMOLISH {
83
80
sub _build_object {
84
81
my ($self ) = @_ ;
85
82
$self -> errormessage(q{ } );
86
- $self -> ok(1);
87
- $self -> warning(0);
88
83
if (not $self -> file) {
89
84
$self -> errorcode(1);
90
85
$self -> errormessage(' No file specified' );
91
- $self -> ok(0);
92
86
return undef ;
93
87
};
94
88
if (not -e $self -> file) {
95
89
$self -> errorcode(1);
96
90
$self -> errormessage(' The file ' .$self -> file.' does not exist' );
97
- $self -> ok(0);
98
91
return undef ;
99
92
};
100
93
if (not -r $self -> file) {
101
94
$self -> errorcode(1);
102
95
$self -> errormessage(' The file ' .$self -> file.' cannot be read' );
103
- $self -> ok(0);
104
96
return undef ;
105
97
};
106
98
if (-d $self -> file) {
107
99
$self -> errorcode(1);
108
100
$self -> errormessage($self -> file.' is a folder (i.e. not an XDI file)' );
109
- $self -> ok(0);
110
101
return undef ;
111
102
};
112
103
my $errcode = 0;
@@ -116,34 +107,8 @@ sub _build_object {
116
107
117
108
return $obj if ($errcode < 0);
118
109
119
- # print $self->file, $/;
120
- # $self->trace;
121
- # print '>>>>>', $errcode, $/;
122
-
123
- # #### see xdifile.h for error codes
124
- # #### see xdifile.c (line 23 and following) for error messages
125
- # if ($errcode < 0) {
126
- # my @errors = ();
127
- # foreach my $i (0 .. 10) {
128
- # push @errors, $obj->_errorstring(-1*2**$i) if (abs($errcode) & 2**$i);
129
- # };
130
- # $self->error(join(", ", @errors));
131
- # $self->ok(0);
132
- # return $obj;
133
- # };
134
- # if ($errcode > 0) {
135
- # my @errors = ();
136
- # foreach my $i (0 .. 4) {
137
- # push @errors, $obj->_errorstring(2**$i) if ($errcode & 2**$i);
138
- # };
139
- # $self->error(join(", ", @errors));
140
- # $self->ok(1);
141
- # $self->warning(1);
142
- # };
143
-
144
110
if (not defined $obj -> _filename) {
145
- $self -> error(' unknown problem reading ' .$self -> file.' as an XDI file' );
146
- $self -> ok(0);
111
+ $self -> errormessage(' unknown problem reading ' .$self -> file.' as an XDI file' );
147
112
return $obj ;
148
113
};
149
114
@@ -356,10 +321,10 @@ Import an XDI file:
356
321
357
322
use Xray::XDI;
358
323
my $xdi = Xray::XDI->new(file=>'data.dat');
359
- if ($xdi->ok ) {
324
+ if ($xdi->errorcode == 0 ) {
360
325
# do stuff
361
326
} else {
362
- print "Uh oh! ", $xdi->error , $/;
327
+ print "Uh oh! ", $xdi->errormessage , $/;
363
328
};
364
329
365
330
Export an XDI file:
@@ -376,16 +341,17 @@ The fully resolved path to the XDI file. Setting this triggers the
376
341
importing of the file and the setting of all other attributes from the
377
342
contents of the file.
378
343
379
- =item C<ok >
344
+ =item C<errormessage >
380
345
381
- This is true when C<file > is properly imported. When false, the
382
- problem will be recorded in the C<error > attribute.
346
+ When an XDI file is imported properly, this is an empty string. When
347
+ import or validation runs into a problem, the explanation will be
348
+ stroed here as a string.
383
349
384
- =item C<error >
350
+ =item C<errorcode >
385
351
386
- When an XDI file is imported properly, this is an empty string. When
387
- import runs into a problem, the explanation will be stroed here as a
388
- string .
352
+ The numeric code returned by C< libxdifile > when a problem is
353
+ encountered. The C< errorcode > always corresponds to the
354
+ C< errormessage > .
389
355
390
356
=item C<xdifile >
391
357
@@ -411,6 +377,10 @@ The element of the absorber.
411
377
412
378
The absorption edge at which the data were measured.
413
379
380
+ =item C<dspacing >
381
+
382
+ The d-spacing (or line spacing) of the mono used in the measurement.
383
+
414
384
=item C<comments >
415
385
416
386
The user supplied comments with all white space and carriage returns
@@ -467,6 +437,31 @@ Alternately,
467
437
## later....
468
438
$xdi -> file('/path/to/file');
469
439
440
+ =item C<required >
441
+
442
+ Test the XDIFile object for whether it contains the metadata items
443
+ B<required > by the XDI spec, C<Mono.d_spacing > , C<Element.symbol > , and
444
+ C<Element.edge > .
445
+
446
+ my $code = $xdi->required;
447
+ print $xdi->error_message, $/ if ($code);
448
+
449
+ =item C<recommended >
450
+
451
+ Test the XDIFile object for whether it contains the metadata items
452
+ B<recommended > by the XDI spec.
453
+
454
+ my $code = $xdi->recommended;
455
+ print $xdi->error_message, $/ if ($code);
456
+
457
+ =item C<validate >
458
+
459
+ Validate a sepcific metadata item against its definition in the XDI
460
+ dictionary.
461
+
462
+ my $code = $xdi->validate($family, $name, $value);
463
+ print $xdi->error_message, $/ if ($code);
464
+
470
465
=item C<labels >
471
466
472
467
Return a list of column labels in the order of appearance in the XDI
@@ -567,17 +562,6 @@ in brackets.
567
562
568
563
=back
569
564
570
- =head1 VALIDATION
571
-
572
- If the sole intent is to validate an XDI file, i.e. to determine
573
- whether or not it conforms to the specification, it should be adequate
574
- to do something like the following:
575
-
576
- $xdi = Xray::XDI->new('somefile.dat');
577
- $is_valid = $xdi->ok;
578
- $problem = $xdi->error if not $is_valid;
579
- undef $xdi;
580
- print "okee dokee!\n" if $is_valid;
581
565
582
566
=head1 DIAGNOSTICS
583
567
@@ -608,6 +592,11 @@ L<Moose>, L<MooseX::NonMoose>
608
592
609
593
=over 4
610
594
595
+ =iten *
596
+
597
+ need a validate method that reads, runs required and recommend, and
598
+ validates all metadata, returning true if no problems found.
599
+
611
600
=item *
612
601
613
602
need an add data column method
0 commit comments