File Coverage

blib/lib/WWW/Arbeitsagentur.pm
Criterion Covered Total %
statement 13 52 25.0
branch 1 14 7.1
condition 0 3 0.0
subroutine 4 7 57.1
pod 3 4 75.0
total 21 80 26.2


line stmt bran cond sub pod time code
1             package WWW::Arbeitsagentur;
2             $VERSION = '0.02';
3              
4 1     1   30056 use Exporter;
  1         4  
  1         80  
5             @ISA = qw(Exporter);
6             @EXPORT_OK = qw(extract_refnumber);
7              
8 1     1   6 use strict;
  1         8  
  1         43  
9 1     1   15 use warnings;
  1         8  
  1         717  
10              
11             sub extract_refnumber{
12 1     1 0 9 my ($text_ref) = @_;
13              
14 1 50       2 if (${$text_ref} =~ m/Referenznummer\D+?([\d]+[-\w]+)/){
  1         14  
15 1         10 return $1;
16             }
17             else{
18 0           return 0;
19             }
20             }
21              
22             sub connect{
23 0     0 1   my ($self) = @_;
24 0           my $mech = $self->mech();
25              
26             # warn "Versuche, Verbindung zur Arbeitsagentur aufzubauen.\n";
27 0           $mech->get("http://www.arbeitsagentur.de");
28 0           $mech->dump_content('connect.html');
29 0 0 0       $mech->success() and $mech->title() eq 'arbeitsagentur.de'
30             or die "Could not connect to www.arbeitsagentur.de\n$!";
31              
32 0 0         unless (eval{
33            
34 0           $self->choose_my_side();
35 0           $mech->dump_content('startpage.html');
36            
37             # die "Konnte nicht zur Seite für ".$self->type()." wechseln.\n" unless $self->mech->success();
38 0 0         $mech->success() or die "Could not switch to page for ".($self->isa('Dewarim::Arbeit::Arbeitnehmer') ? 'Arbeitnehmer' : 'Arbeitgeber').".\n";
    0          
39            
40 0           1;
41             }) {
42 0           print STDERR $@;
43 0           return 0;
44             }
45              
46 0           return 1;
47             }
48              
49             sub logout{
50 0     0 1   my ($self) = @_;
51 0           my $mech = $self->mech;
52              
53 0           $mech->submit_form('form_number' => 1,
54             'button' => 'abmelden',
55             );
56 0           $mech->dump_content('logout_page.html');
57 0           return $mech->success();
58             }
59              
60             sub login{
61 0     0 1   my ($self) = @_;
62 0           $self->connect();
63              
64 0           warn "Folge Link zur Anmeldung.\n";
65 0           my $mech = $self->mech();
66 0           $mech->dump_content();
67            
68 0           $mech->follow_link('text_regex'
69             => qr!Zur\sAnmeldung!);
70            
71 0           $mech->dump_content('login_page.html');
72 0 0         unless ($mech->success()) {
73 0           print STDERR "Login failed - could not find Login form.
\n";
74 0           return 0;
75             }
76            
77 0           warn "Submitting login form.\n";
78 0           $mech->submit_form("form_number" => 3,
79             "fields" => {
80             "j_username" => $self->user,
81             "j_password" => $self->pw,
82             },
83             "button" => "send"
84             );
85            
86              
87 0           $mech->dump_content('login_result.html');
88              
89 0 0         if ($mech->content() =~ m/Sie sind angemeldet als/){
90 0           warn("Login was successful.\n");
91 0           return 1;
92             }
93             else{
94 0           warn("*** Warning: Login failed! ***");
95 0           warn("Please check if your login name and password are ok and\n".
96             "if you can connect via browser to arbeitsagentur.de.\n");
97 0           sleep(120);
98 0           return 0;
99             }
100             }
101              
102             1;
103              
104             =head1 NAME
105              
106             WWW::Arbeitsagentur - Search for jobs via arbeitsagentur.de
107              
108             =head1 SYNOPSIS
109             # example for using the quick-search module:
110             use WWW::Arbeitsagentur::Search::FastSearchForWork;
111             my $search = WWW::Arbeitsagentur::Search::FastSearchForWork->new(
112             # where to save your files (optional)
113             path => "download/",
114             # search for a normal job (instead of temp/contract work etc.)
115             job_typ => 1,
116             # only save jobs whose postal code matches this regex
117             plz_filter => qr/.+/,
118             # job title
119             beruf => 'Fachinformatiker/in - Anwendungsentwicklung',
120             );
121              
122             # how many pages were found?
123             my $result = $search->search();
124              
125             # Access the results:
126             my @pages = $search->results();
127            
128             =head1 DESCRIPTION
129              
130             WWW::Arbeitsagentur provides access to the search engine of the federal job agency of Germany. You may search either for jobs or applicants, if you have an account. Search results are collected and may be filtered and stored for offline-use.
131              
132             =head1 METHODS
133              
134             =head2 $search->connect(Z<>)
135              
136             Builds up a connection to http://www.arbeitsagentur.de
137              
138             I
139              
140             B<0> - an error occurred
141              
142             B<1> - success
143              
144             Dies if attempt to connect fails completely.
145              
146             =head2 $search->login(Z<>)
147              
148             After establishing a connection, you can login with your account data, either as an applicant or as a recruiter. Your Perl setup has be SSL-capable, ie. Crypt::SSLeay and (on Windows) the corresponding dlls have to be installed.
149              
150             I
151              
152             B<0> - an error occurred
153              
154             B<1> - success
155              
156             =head2 $search->logout(Z<>)
157              
158             Logout from the Arbeitsagentur. Otherwise, you will get a warning the next time you log in via the web interface.
159              
160             I
161              
162             B<0> - an error occurred
163              
164             B<1> - success
165              
166             =head1 MOTIVATIONS
167              
168             If you use the search engine on Arbeitsagentur (which is the largest one in Germany for searching jobs or applicants), you may wish to filter certain job offers or applicants permanently, either because you already know them or they are not what you seek. Normally, you will receive the same results if you search again the next day and so you need to step through all the result pages again.
169             WWW::Arbeitsagentur allows you to build a script which searches for jobs/applicants automatically, filtering and displaying results in a more user friendly way than the current web interface of the Arbeitsagentur.
170              
171             This module is a rewrite of an existing project of mine. The new version will include tests, more documentation and a better interface, as well as an easy way to install via CPAN / Module::Build.
172              
173             =head1 TODO
174              
175             The module stands incomplete, as some parts will have to be rewritten and ported over from http://arbeitssuche.sf.net. So, if you need a working solution _now_, try the SourceForge version.
176              
177             =head1 AUTHOR
178              
179             Ingo Wiarda; E-Mail: Ingo_Wiarda@web.de
180              
181             =head1 COPYRIGHT AND LICENSE
182              
183             WWW::Arbeitsagentur is written and mantained by Ingo Wiarda.
184             It is based upon "Projekt Arbeit" on arbeitssuche.sf.net,
185             Copyright (C) 2004-2006 by Ingo Wiarda, Stefan Rother
186              
187             This library is free software; you can redistribute it and/or modify
188             it under the same terms as Perl itself.