Blame Detector.pm

Packit 67f6e7
package Encode::Detect::Detector;
Packit 67f6e7
Packit 67f6e7
# * ***** BEGIN LICENSE BLOCK *****
Packit 67f6e7
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
Packit 67f6e7
#
Packit 67f6e7
# The contents of this file are subject to the Mozilla Public License Version
Packit 67f6e7
# 1.1 (the "License"); you may not use this file except in compliance with
Packit 67f6e7
# the License. You may obtain a copy of the License at
Packit 67f6e7
# http://www.mozilla.org/MPL/
Packit 67f6e7
#
Packit 67f6e7
# Software distributed under the License is distributed on an "AS IS" basis,
Packit 67f6e7
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
Packit 67f6e7
# for the specific language governing rights and limitations under the
Packit 67f6e7
# License.
Packit 67f6e7
#
Packit 67f6e7
# The Original Code is Encode::Detect wrapper
Packit 67f6e7
#
Packit 67f6e7
# The Initial Developer of the Original Code is
Packit 67f6e7
# Proofpoint, Inc.
Packit 67f6e7
# Portions created by the Initial Developer are Copyright (C) 2005
Packit 67f6e7
# the Initial Developer. All Rights Reserved.
Packit 67f6e7
#
Packit 67f6e7
# Contributor(s):
Packit 67f6e7
#
Packit 67f6e7
# Alternatively, the contents of this file may be used under the terms of
Packit 67f6e7
# either the GNU General Public License Version 2 or later (the "GPL"), or
Packit 67f6e7
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
Packit 67f6e7
# in which case the provisions of the GPL or the LGPL are applicable instead
Packit 67f6e7
# of those above. If you wish to allow use of your version of this file only
Packit 67f6e7
# under the terms of either the GPL or the LGPL, and not to allow others to
Packit 67f6e7
# use your version of this file under the terms of the MPL, indicate your
Packit 67f6e7
# decision by deleting the provisions above and replace them with the notice
Packit 67f6e7
# and other provisions required by the GPL or the LGPL. If you do not delete
Packit 67f6e7
# the provisions above, a recipient may use your version of this file under
Packit 67f6e7
# the terms of any one of the MPL, the GPL or the LGPL.
Packit 67f6e7
#
Packit 67f6e7
# ***** END LICENSE BLOCK *****
Packit 67f6e7
Packit 67f6e7
use strict;
Packit 67f6e7
use warnings;
Packit 67f6e7
Packit 67f6e7
our $VERSION = "1.01";
Packit 67f6e7
Packit 67f6e7
require DynaLoader;
Packit 67f6e7
our @ISA=qw(DynaLoader Exporter);
Packit 67f6e7
Encode::Detect::Detector->bootstrap($VERSION);
Packit 67f6e7
our @EXPORT=qw(detect);
Packit 67f6e7
Packit 67f6e7
Packit 67f6e7
1;
Packit 67f6e7
Packit 67f6e7
__END__
Packit 67f6e7
Packit 67f6e7
=head1 NAME
Packit 67f6e7
Packit 67f6e7
Encode::Detect::Detector - Detects the encoding of data
Packit 67f6e7
Packit 67f6e7
=head1 SYNOPSIS
Packit 67f6e7
Packit 67f6e7
  use Encode::Detect::Detector;
Packit 67f6e7
  my $charset = detect($octets);
Packit 67f6e7
Packit 67f6e7
  my $d = new Encode::Detect::Detector;
Packit 67f6e7
  $d->handle($octets);
Packit 67f6e7
  $d->handle($more_octets);
Packit 67f6e7
  $d->end;
Packit 67f6e7
  my $charset = $d->getresult;
Packit 67f6e7
Packit 67f6e7
=head1 DESCRIPTION
Packit 67f6e7
Packit 67f6e7
This module provides an interface to Mozilla's universal charset
Packit 67f6e7
detector, which detects the charset used to encode data.
Packit 67f6e7
Packit 67f6e7
=head1 METHODS
Packit 67f6e7
Packit 67f6e7
=head2 $charset = Encode::Detect::Detector->detect($octets)
Packit 67f6e7
Packit 67f6e7
Detect the charset used to encode the data in $octets and return the
Packit 67f6e7
charset's name.  Returns undef if the charset cannot be determined
Packit 67f6e7
with sufficient confidence.
Packit 67f6e7
Packit 67f6e7
=head2 $d = Encode::Detect::Detector->new()
Packit 67f6e7
Packit 67f6e7
Creates a new C<Encode::Detect::Detector> object and returns it.
Packit 67f6e7
Packit 67f6e7
=head2 $d->handle($octets)
Packit 67f6e7
Packit 67f6e7
Provides an additional chunk of data to be examined by the detector.
Packit 67f6e7
May be called multiple times.
Packit 67f6e7
Packit 67f6e7
Returns zero on success, nonzero if a memory allocation failed.
Packit 67f6e7
Packit 67f6e7
=head2 $d->eof
Packit 67f6e7
Packit 67f6e7
Informs the detector that there is no more data to be examined.  In
Packit 67f6e7
many cases, this is necessary in order for the detector to make a
Packit 67f6e7
decision on the charset.
Packit 67f6e7
Packit 67f6e7
=head2 $d->reset
Packit 67f6e7
Packit 67f6e7
Resets the detector to its initial state.
Packit 67f6e7
Packit 67f6e7
=head2 $d->getresult
Packit 67f6e7
Packit 67f6e7
Returns the name of the detected charset or C<undef> if no charset has
Packit 67f6e7
(yet) been decided upon.  May be called at any time.
Packit 67f6e7
Packit 67f6e7
=head1 SEE ALSO
Packit 67f6e7
Packit 67f6e7
L<Encode::Detect>
Packit 67f6e7
Packit 67f6e7
=head1 AUTHOR
Packit 67f6e7
Packit 67f6e7
John Gardiner Myers <jgmyers@proofpoint.com>
Packit 67f6e7
Packit 67f6e7
=head1 SUPPORT
Packit 67f6e7
Packit 67f6e7
For help and thank you notes, e-mail the author directly.  To report a
Packit 67f6e7
bug, submit a patch, or add to the wishlist please visit the CPAN bug
Packit 67f6e7
manager at: F<http://rt.cpan.org>
Packit 67f6e7
Packit 67f6e7