~ubuntu-branches/ubuntu/precise/padre/precise

« back to all changes in this revision

Viewing changes to lib/Padre/Task/HTTPClient.pm

  • Committer: Bazaar Package Importer
  • Author(s): Damyan Ivanov
  • Date: 2009-10-29 17:40:10 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20091029174010-yu27elyiv9izv0dv
Tags: 0.48.ds2-1
* New Upstream Version
  + new dependencies:
    - libdevel-refactor-perl 0.05
    - libfile-next-perl 1.04
    - libpod-perldoc-perl 3.15
    - libversion-perl (perl 5.10)
    - pip 0.13
  + new Recommends:
    - libformat-human-bytes-perl
  + dropped dependdencies
    - libcapture-tiny-perl
    - libfile-sharedir-par-perl
    - libpar-perl
  + bump libfile-which-perl, libppi-per, libppix-editortools-perl,
    libtest-script-perl and libwx-perl-processstream-perl dependencies
  + update translators list in d/copyright
  + add copyright holders for code borrowed from ExtUtils::MakeMaker
  + rules: drop empty Padre::Wx::Dialog::OpenResource::SearchTask manpage
  + refresh disable-tcp-server.patch
  + drop patches applied upstream: fix-perl-interpreter-path.patch,
    fix-pod-errors.patch and fix-whatis.patch
* Standards-Version: 3.8.3 (no changes)
* update debian/repack.sh to remove script/padre.exe,
  share/padre-splash-ccnc.bmp and  share/doc/perlopref.pod and plug it
  into debian/watch; describe repackaging in debian/copyright
* copyright: update
* update lintian override of template/example scripts not being
  executable
* add fix-helpprovider-with-no-perldoc.patch so that the Help browser does
  not hang because of the missing perlopref.pod
* update README.debian with regard to repackaging

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
package Padre::Task::HTTPClient;
2
2
 
 
3
use 5.008;
3
4
use strict;
4
5
use warnings;
5
 
use Params::Util qw{_CODE _INSTANCE};
6
 
use URI              ();
7
 
use HTTP::Request    ();
8
 
use Padre::Task::LWP ();
9
 
 
10
 
our $VERSION = '0.42';
11
 
our @ISA     = 'Padre::Task::LWP';
 
6
 
 
7
# Use all modules which may provide services for us:
 
8
 
 
9
our $VERSION = '0.48';
12
10
 
13
11
=pod
14
12
 
15
13
=head1 NAME
16
14
 
17
 
Padre::Task::HTTPClient - Generic http client background processing task
18
 
 
19
 
=head1 SYNOPSIS
 
15
Padre::Task::HTTPClient - HTTP client for Padre
20
16
 
21
17
=head1 DESCRIPTION
22
18
 
23
 
Sending and receiving data via HTTP.
 
19
Padre::Task::HTTPClient provies a common API for HTTP access to Padre.
 
20
 
 
21
As we don't want a specific HTTP client module dependency to a
 
22
network-independent application like Padre, this module searches
 
23
for installed HTTP client modules and uses one of them.
 
24
 
 
25
If none of the "child" modules could be loaded (no HTTP support at all
 
26
on this computer), it fails and returns nothing (scalar undef).
 
27
 
 
28
=head1 METHODS
 
29
 
 
30
=head2 new
 
31
 
 
32
  my $http = Padre::Task::HTTPClient->new();
 
33
 
 
34
The C<new> constructor lets you create a new B<Padre::Task::HTTPClient> object.
 
35
 
 
36
Returns a new B<Padre::Task::HTTPClient> or dies on error.
24
37
 
25
38
=cut
26
39
 
27
 
# TODO this should probably run later,
28
 
# not when the plugin is enabled
29
40
sub new {
 
41
 
30
42
        my $class = shift;
31
43
 
32
 
        # Prepare the information to send
33
 
        my %data = (
34
 
                padre  => $VERSION,
35
 
                perl   => $],
36
 
                osname => $^O,
37
 
        );
38
 
        if ( $0 =~ /padre$/ ) {
39
 
                my $dir = $0;
40
 
                $dir =~ s/padre$//;
41
 
                my $revision = Padre::Util::svn_directory_revision($dir);
42
 
                if ( -d "$dir.svn" ) {
43
 
                        $data{svn} = $revision;
44
 
                }
 
44
        my %args = @_;
 
45
 
 
46
        return if ( !defined( $args{URL} ) ) or ( $args{URL} eq '' );
 
47
 
 
48
        # Prepare information
 
49
        $args{headers}->{'X-Padre'} ||= 'Padre version ' . $VERSION . ' ' . Padre::Util::revision();
 
50
        $args{method} ||= 'GET';
 
51
 
 
52
        my $self;
 
53
 
 
54
        # Each module will be tested and the first working one should return
 
55
        # a object, all others should return nothing (undef)
 
56
        for ('LWP') {
 
57
                require 'Padre/Task/HTTPClient/' . $_ . '.pm';
 
58
                $self = "Padre::Task::HTTPClient::$_"->new(%args);
 
59
                next unless defined($self);
 
60
                return $self;
45
61
        }
46
62
 
47
 
        # Generate the request URL
48
 
        my $url = URI->new('http://peride.org/popularity');
49
 
        $url->query_form( \%data, ';' );
 
63
        return;
50
64
 
51
 
        # Hand off to the parent constructor
52
 
        return $class->SUPER::new( request => HTTP::Request->new( GET => $url->as_string ) );
53
65
}
54
66
 
 
67
#=head2 atime
 
68
#
 
69
#  $file->atime;
 
70
#
 
71
#Returns the last-access time of the file.
 
72
#
 
73
#This is usually not possible for non-local files, in these cases, undef
 
74
#is returned.
 
75
#
 
76
#=cut
 
77
#
 
78
## Fallback if the module has no such function:
 
79
#sub atime {
 
80
#       return;
 
81
#}
 
82
#
55
83
1;
56
84
 
57
 
__END__
58
 
 
59
 
=head1 SEE ALSO
60
 
 
61
 
This class inherits from C<Padre::Task> and its instances can be scheduled
62
 
using C<Padre::TaskManager>.
63
 
 
64
 
The transfer of the objects to and from the worker threads is implemented
65
 
with L<Storable>.
66
 
 
67
 
=head1 AUTHOR
68
 
 
69
 
Steffen Mueller C<smueller@cpan.org>
70
 
 
71
 
=head1 COPYRIGHT AND LICENSE
72
 
 
73
 
Copyright 2008-2009 The Padre development team as listed in Padre.pm.
74
 
 
75
 
This program is free software; you can redistribute it and/or
76
 
modify it under the same terms as Perl 5 itself.
77
 
 
78
 
=cut
79
 
 
80
85
# Copyright 2008-2009 The Padre development team as listed in Padre.pm.
81
86
# LICENSE
82
87
# This program is free software; you can redistribute it and/or