File: PDF.pm

package info (click to toggle)
liburi-title-perl 1.904-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 188 kB
  • sloc: perl: 533; makefile: 6
file content (51 lines) | stat: -rw-r--r-- 1,110 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package URI::Title::PDF;
$URI::Title::PDF::VERSION = '1.904';
use warnings;
use strict;

sub types {(
  'application/pdf',
)}

sub title {
  my ($class, $url, $data, $type) = @_;

  my %fields = ();
  my $content = URI::Title::_get_end($url) or return;
  foreach my $i (qw(Producer Creator CreationDate Author Title Subject)) {
    my @parts = $content =~ m#/$i \((.*?)\)#mgs;
    $fields{$i} = $parts[-1]; # grab the last one, hopefully right
  }

  my $title = "";
  my @parts = ();
  if ($fields{Title}) {
    push @parts, "$fields{Title}";
    if ($fields{Author}) { push @parts, "by $fields{Author}"; }
    if ($fields{Subject}) { push @parts, "($fields{Subject})"; }
  }
  if ($fields{Creator} and $fields{Creator} ne 'Not Available') {
    push @parts, "creator: $fields{Creator}";
  }
  if ($fields{Producer} and $fields{Producer} ne 'Not Available') {
    push @parts, "produced: $fields{Producer}";
  }
  $title = join(' ', @parts);
  return $title;
}

1;

__END__

=for Pod::Coverage::TrustPod types title

=head1 NAME

URI::Title::PDF - get titles of PDF files

=head1 VERSION

version 1.904

=cut