~ubuntu-branches/ubuntu/trusty/swish-e/trusty

« back to all changes in this revision

Viewing changes to filters/SWISH/Filter.pm.in

  • Committer: Bazaar Package Importer
  • Author(s): Ludovic Drolez
  • Date: 2008-09-25 21:52:31 UTC
  • mfrom: (4.1.4 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080925215231-vk46pq42o533syg2
Tags: 2.4.5-5
swish.cgi was not working. Fixed with a 1 char patch. Closes: #500154

Show diffs side-by-side

added added

removed removed

Lines of Context:
124
124
 
125
125
=over 4
126
126
 
127
 
=item $filter = SWISH::Filter->new()
 
127
=item $filter = SWISH::Filter-E<gt>new()
128
128
 
129
129
This creates a SWISH::Filter object.  You may pass in options as a list or a hash reference.
130
130
 
131
131
=back
132
132
 
133
 
=head2 SWISH::Filter->new Options
 
133
=head2 SWISH::Filter-E<gt>new Options
134
134
 
135
135
There is currently only one option that can be passed in to new():
136
136
 
217
217
 
218
218
 
219
219
 
220
 
=item $doc_object = $filter->convert();
 
220
=item $doc_object = $filter-E<gt>convert();
221
221
 
222
222
This method filters a document.  Returns an object of the class SWISH::Filter::document
223
223
or undefined if passed in an empty document, a filename that cannot be read off disk, or
410
410
 
411
411
 
412
412
 
413
 
=item $filter->mywarn()
 
413
=item $filter-E<gt>mywarn()
414
414
 
415
415
Internal function used for writing warning messages to STDERR if
416
416
$ENV{FILTER_DEBUG} is set.  Set the environment variable FILTER_DEBUG before
424
424
    print STDERR @_,"\n" if $ENV{FILTER_DEBUG};
425
425
}
426
426
 
427
 
=item @filters = $filter->filter_list;
 
427
=item @filters = $filter-E<gt>filter_list;
428
428
 
429
429
Returns a list of filter objects installed.
430
430
 
513
513
    $self->filter_list( [ sort { $a->type <=> $b->type || $a->priority <=> $b->priority } @filters ] );
514
514
}
515
515
 
516
 
=item @filter = $filter->can_filter( $content_type );
 
516
=item @filter = $filter-E<gt>can_filter( $content_type );
517
517
 
518
518
This is useful for testing to see if a mimetype might be handled by SWISH::Filter
519
519
wihtout having to pass in a document.  Helpful if doing HEAD requests.
520
520
 
521
521
Returns an array of filters that can handle this type of document
522
522
 
 
523
=back
 
524
 
523
525
=cut
524
526
 
525
527
sub can_filter {
582
584
-S fs has no effect since the program is run once per document.
583
585
 
584
586
Once a filter returns something other than undef no more filters will be
585
 
called.  If the filter calls $filter->set_continue then processing will
 
587
called.  If the filter calls $filter-E<gt>set_continue then processing will
586
588
continue as if the file was not filtered.  For example, a filter can uncompress
587
 
data and then set $filter->set_continue and let other filters process the
 
589
data and then set $filter-E<gt>set_continue and let other filters process the
588
590
document.
589
591
 
590
592
 
831
833
=over 4
832
834
 
833
835
 
834
 
=item $doc_ref = $doc_object->fetch_doc_reference;
 
836
=item $doc_ref = $doc_object-E<gt>fetch_doc_reference;
835
837
 
836
838
Returns a scalar reference to the document.  This can be used when the filter
837
839
can operate on the document in memory (or if an external program expects the input
839
841
 
840
842
If the file is currently on disk then it will be read into memory.  If the file was stored
841
843
in a temporary file on disk the file will be deleted once read into memory.
842
 
The file will be read in binmode if $doc->is_binary is true.
 
844
The file will be read in binmode if $doc-E<gt>is_binary is true.
843
845
 
844
 
Note that $doc_object->fetch_doc is an alias.
 
846
Note that $doc_object-E<gt>fetch_doc is an alias.
845
847
 
846
848
=cut
847
849
 
858
860
*fetch_doc = *fetch_doc_reference;
859
861
 
860
862
 
861
 
=item $was_filtered = $doc_object->was_filtered
 
863
=item $was_filtered = $doc_object-E<gt>was_filtered
862
864
 
863
865
Returns true if some filter processed the document
864
866
 
869
871
    return $self->filters_used ? 1 : 0;
870
872
}
871
873
 
872
 
=item $content_type = $doc_object->content_type;
 
874
=item $content_type = $doc_object-E<gt>content_type;
873
875
 
874
876
Fetches the current content type for the document.
875
877
 
884
886
    return $_[0]->{content_type} || '';
885
887
}
886
888
 
887
 
=item $type = $doc_object->swish_parser_type
 
889
=item $type = $doc_object-E<gt>swish_parser_type
888
890
 
889
891
Returns a parser type based on the content type
890
892
 
912
914
    return;
913
915
}
914
916
 
915
 
=item $doc_object->is_binary
 
917
=item $doc_object-E<gt>is_binary
916
918
 
917
919
Returns true if the document's content-type does not match "text/".
918
920
 
929
931
 
930
932
=over 4
931
933
 
932
 
=item $file_name = $doc_object->fetch_filename;
 
934
=item $file_name = $doc_object-E<gt>fetch_filename;
933
935
 
934
936
Returns a path to the document as stored on disk.
935
937
This name can be passed to external programs (e.g. catdoc) that expect input
938
940
If the document is currently in memory then a temporary file will be created.  Do not expect
939
941
the file name passed to be the real path of the document.
940
942
 
941
 
The file will be written in binmode if $doc->is_binary is true.
 
943
The file will be written in binmode if $doc-E<gt>is_binary is true.
942
944
 
943
945
This method is not normally used by end-users of SWISH::Filter.
944
946
 
955
957
        : $self->{cur_doc};
956
958
}
957
959
 
958
 
=item $doc_object->set_continue;
 
960
=item $doc_object-E<gt>set_continue;
959
961
 
960
962
Processing will continue to the next filter if this is set to a true value.
961
963
This should be set for filters that change encodings or uncompress documents.
976
978
 
977
979
 
978
980
 
979
 
=item $doc_object->set_content_type( $type );
 
981
=item $doc_object-E<gt>set_content_type( $type );
980
982
 
981
983
Sets the content type for a document.
982
984
 
1033
1035
}
1034
1036
 
1035
1037
 
1036
 
=item $doc_object->name
 
1038
=item $doc_object-E<gt>name
1037
1039
 
1038
1040
Fetches the name of the current file.  This is useful for printing out the
1039
1041
name of the file in an error message.
1040
 
This is the name passed in to the SWISH::Filter->convert method.
 
1042
This is the name passed in to the SWISH::Filter-E<gt>convert method.
1041
1043
It is optional and thus may not always be set.
1042
1044
 
1043
1045
    my $name = $doc_object->name || 'Unknown name';
1044
1046
    warn "File '$name': failed to convert -- file may be corrupt\n";
1045
1047
 
1046
1048
 
1047
 
=item $doc_object->user_data
 
1049
=item $doc_object-E<gt>user_data
1048
1050
 
1049
1051
Fetches the the user_data passed in to the filter.
1050
 
This can be any data or data structure passed into SWISH::Filter->new.
 
1052
This can be any data or data structure passed into SWISH::Filter-E<gt>new.
1051
1053
 
1052
1054
This is an easy way to pass special parameters into your filters.
1053
1055
 
1060
1062
       ...
1061
1063
    }
1062
1064
 
 
1065
=back
 
1066
 
1063
1067
=cut
1064
1068
 
1065
1069
sub AUTOLOAD {
1100
1104
 
1101
1105
=over 4
1102
1106
 
1103
 
=item $self->type
 
1107
=item $self-E<gt>type
1104
1108
 
1105
1109
This method fetches the type of the filter.  The value returned sets the
1106
1110
primary sort key for sorting the filters.  You can override this in your
1114
1118
 
1115
1119
sub type { 2 };
1116
1120
 
1117
 
=item $self->priority
 
1121
=item $self-E<gt>priority
1118
1122
 
1119
1123
This method fetches the priority of the filter.  The value returned sets the
1120
1124
secondary sort key for sorting the filters.  You can override this in your
1131
1135
 
1132
1136
sub priority { 50 };  # default priority
1133
1137
 
1134
 
=item @types = $self->mimetypes
 
1138
=item @types = $self-E<gt>mimetypes
1135
1139
 
1136
1140
Returns the list of mimetypes (as regular expressions) set for the filter.
1137
1141
 
1149
1153
    return @{ $self->{mimetypes} };
1150
1154
}
1151
1155
 
1152
 
=item $pattern = $self->can_filter_mimetype( $content_type )
 
1156
=item $pattern = $self-E<gt>can_filter_mimetype( $content_type )
1153
1157
 
1154
1158
Returns true if passed in content type matches one of the filter's mimetypes
1155
1159
Returns the pattern that matched.
1178
1182
    print STDERR "Filter: $self: ", @_,"\n" if $ENV{FILTER_DEBUG};
1179
1183
}
1180
1184
 
1181
 
=item $boolean = $self->set_programs( @program_list );
 
1185
=item $boolean = $self-E<gt>set_programs( @program_list );
1182
1186
 
1183
1187
Returns true if all the programs listed in @program_list are found
1184
1188
and can be executed as the current user.  Creates a method for each
1219
1223
}
1220
1224
 
1221
1225
 
1222
 
=item $path = $self->find_binary( $prog );
 
1226
=item $path = $self-E<gt>find_binary( $prog );
1223
1227
 
1224
1228
Use in a filter's new() method to test for a necesary program located in $PATH.
1225
1229
Returns the path to the program or undefined if not found or does not pass the -x
1301
1305
 
1302
1306
}
1303
1307
 
1304
 
=item $bool = $self->use_modules( @module_list );
 
1308
=item $bool = $self-E<gt>use_modules( @module_list );
1305
1309
 
1306
1310
Attempts to load each of the module listed and calls its import() method.
1307
1311
 
1312
1316
A warning message is displayed if the FILTER_DEBUG environment variable is true.
1313
1317
Returns $self if no error.
1314
1318
 
1315
 
=back
1316
1319
 
1317
1320
=cut
1318
1321
 
1338
1341
    return $self;
1339
1342
}
1340
1343
 
1341
 
=item $doc_ref = $self->run_program( $program, @args );
 
1344
=item $doc_ref = $self-E<gt>run_program( $program, @args );
1342
1345
 
1343
1346
Runs $program with @args.  Must pass in @args.
1344
1347
 
1372
1375
    close $fh;
1373
1376
 
1374
1377
    # When using IPC::Open3 need to reap the processes.
1375
 
    waitpid $self->{pid}, 0 if delete $self->{pid};
 
1378
    waitpid delete $self->{pid}, 0 if $self->{pid};
1376
1379
 
1377
1380
    return $output;
1378
1381
}