initial screenshot attempt
[imager-screenshot.git] / Screenshot.pm
CommitLineData
a9735f1a
TC
1package Imager::Screenshot;\r
2use strict;\r
3use vars qw(@ISA $VERSION @EXPORT_OK);\r
4use Imager;\r
5require Exporter;\r
6\r
7push @ISA, 'Exporter';\r
8@EXPORT_OK = 'screenshot';\r
9\r
10BEGIN {\r
11 require Exporter;\r
12 @ISA = qw(Exporter);\r
13 $VERSION = '0.001';\r
14 eval {\r
15 # try XSLoader first, DynaLoader has annoying baggage\r
16 require XSLoader;\r
17 XSLoader::load('Imager::Screenshot' => $VERSION);\r
18 1;\r
19 } or do {\r
20 require DynaLoader;\r
21 push @ISA, 'DynaLoader';\r
22 bootstrap Imager::Screenshot $VERSION;\r
23 }\r
24}\r
25\r
26sub screenshot {\r
27 # lose the class if called as a method\r
28 @_ % 2 == 1 and shift;\r
29\r
30 my %opts = (decor => 1, @_);\r
31\r
32 my $result;\r
33 if (!@_) {\r
34 my $result =\r
35 defined &win32 ? win32(0) :\r
36 defined &x11 ? x11(0) :\r
37 die "No drivers enabled\n";\r
38 }\r
39 if (defined $opts{hwnd}) {\r
40 defined &win32\r
41 or die "Win32 driver not enabled\n";\r
42 $result = win32($opts{hwnd}, $opts{decor});\r
43 }\r
44 elsif (defined $opts{id}) { # X11 window id\r
45 defined &x11\r
46 or die "X11 driver not enabled\n";\r
47 $result = x11($opts{id});\r
48 }\r
49\r
50 unless ($result) {\r
51 Imager->_set_error(Imager->_error_as_msg());\r
52 return;\r
53 }\r
54 \r
55 return $result;\r
56}\r
57\r
58sub have_win32 {\r
59 defined &win32;\r
60}\r
61\r
62sub have_x11 {\r
63 defined &x11;\r
64}\r
65\r
66# everything else is XS\r
671;\r
68\r
69__END__\r
70\r
71=head1 NAME\r
72\r
73Imager::Screenshot - screenshot to an Imager image\r
74\r
75=head1 SYNOPSIS\r
76\r
77 use Imager::Screenshot 'screeshot';\r
78\r
79 # whole screen\r
80 my $img = screenshot();\r
81\r
82=head1 DESCRIPTION\r
83\r
84\r
85=head1 AUTHOR\r
86\r
87Tony Cook <tonyc@cpan.org>\r
88\r
89=cut\r
90\r
91\r