diff options
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | Changes | 8 | ||||
-rw-r--r-- | MANIFEST | 9 | ||||
-rw-r--r-- | Makefile.PL | 18 | ||||
-rw-r--r-- | README | 40 | ||||
-rw-r--r-- | lib/DJabberd/Plugin/EntityTime.pm | 102 | ||||
-rw-r--r-- | t/00-load.t | 9 | ||||
-rw-r--r-- | t/boilerplate.t | 48 | ||||
-rw-r--r-- | t/pod-coverage.t | 6 | ||||
-rw-r--r-- | t/pod.t | 6 |
10 files changed, 250 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..10b5458 --- /dev/null +++ b/.gitignore | |||
@@ -0,0 +1,4 @@ | |||
1 | META.yml | ||
2 | Makefile | ||
3 | /blib | ||
4 | /pm_to_blib | ||
@@ -0,0 +1,8 @@ | |||
1 | Revision history for DJabberd-Plugin-EntityTime | ||
2 | |||
3 | 0.02 2007-08-03 | ||
4 | Fixed xmlns on XEP-0202 response | ||
5 | |||
6 | 0.01 2007-08-03 | ||
7 | First version, released on an unsuspecting world. | ||
8 | |||
diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..73aafd0 --- /dev/null +++ b/MANIFEST | |||
@@ -0,0 +1,9 @@ | |||
1 | Changes | ||
2 | MANIFEST | ||
3 | Makefile.PL | ||
4 | README | ||
5 | lib/DJabberd/Plugin/EntityTime.pm | ||
6 | t/00-load.t | ||
7 | t/boilerplate.t | ||
8 | t/pod-coverage.t | ||
9 | t/pod.t | ||
diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..ce0d492 --- /dev/null +++ b/Makefile.PL | |||
@@ -0,0 +1,18 @@ | |||
1 | use strict; | ||
2 | use warnings; | ||
3 | use ExtUtils::MakeMaker; | ||
4 | |||
5 | WriteMakefile( | ||
6 | NAME => 'DJabberd::Plugin::EntityTime', | ||
7 | AUTHOR => 'Edward Rudd <urkle@outoforder.cc>', | ||
8 | VERSION_FROM => 'lib/DJabberd/Plugin/EntityTime.pm', | ||
9 | ABSTRACT_FROM => 'lib/DJabberd/Plugin/EntityTime.pm', | ||
10 | PL_FILES => {}, | ||
11 | PREREQ_PM => { | ||
12 | 'Test::More' => 0, | ||
13 | 'DJabberd' => 0.83, | ||
14 | }, | ||
15 | DISTNAME => 'DJabberd-EntityTime', | ||
16 | dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, | ||
17 | clean => { FILES => 'DJabberd-Plugin-EntityTime-*' }, | ||
18 | ); | ||
@@ -0,0 +1,40 @@ | |||
1 | DJabberd-Plugin-EntityTime | ||
2 | |||
3 | Implements XEP-0090 and XEP-0202 for DJabberd | ||
4 | |||
5 | INSTALLATION | ||
6 | |||
7 | To install this module, run the following commands: | ||
8 | |||
9 | perl Makefile.PL | ||
10 | make | ||
11 | make test | ||
12 | make install | ||
13 | |||
14 | |||
15 | SUPPORT AND DOCUMENTATION | ||
16 | |||
17 | After installing, you can find documentation for this module with the perldoc command. | ||
18 | |||
19 | perldoc DJabberd::Plugin::EntityTime | ||
20 | |||
21 | You can also look for information at: | ||
22 | |||
23 | Search CPAN | ||
24 | http://search.cpan.org/dist/DJabberd-Plugin-EntityTime | ||
25 | |||
26 | CPAN Request Tracker: | ||
27 | http://rt.cpan.org/NoAuth/Bugs.html?Dist=DJabberd-Plugin-EntityTime | ||
28 | |||
29 | AnnoCPAN, annotated CPAN documentation: | ||
30 | http://annocpan.org/dist/DJabberd-Plugin-EntityTime | ||
31 | |||
32 | CPAN Ratings: | ||
33 | http://cpanratings.perl.org/d/DJabberd-Plugin-EntityTime | ||
34 | |||
35 | COPYRIGHT AND LICENCE | ||
36 | |||
37 | Copyright (C) 2007 Edward Rudd | ||
38 | |||
39 | This program is free software; you can redistribute it and/or modify it | ||
40 | under the same terms as Perl itself. | ||
diff --git a/lib/DJabberd/Plugin/EntityTime.pm b/lib/DJabberd/Plugin/EntityTime.pm new file mode 100644 index 0000000..b59cff6 --- /dev/null +++ b/lib/DJabberd/Plugin/EntityTime.pm | |||
@@ -0,0 +1,102 @@ | |||
1 | package DJabberd::Plugin::EntityTime; | ||
2 | |||
3 | use warnings; | ||
4 | use strict; | ||
5 | use base 'DJabberd::Plugin'; | ||
6 | |||
7 | use POSIX qw(strftime); | ||
8 | |||
9 | our $logger = DJabberd::Log->get_logger(); | ||
10 | |||
11 | =head1 NAME | ||
12 | |||
13 | DJabberd::Plugin::EntityTime - Implements XEP-0090 and XEP-0202 | ||
14 | |||
15 | =head1 VERSION | ||
16 | |||
17 | Version 0.02 | ||
18 | |||
19 | =cut | ||
20 | |||
21 | our $VERSION = '0.02'; | ||
22 | |||
23 | =head1 SYNOPSIS | ||
24 | |||
25 | Implements XEP-0090 and XEP-0202 | ||
26 | |||
27 | <Vhost mydomain.com> | ||
28 | <Plugin DJabberd::Plugin::EntityTime /> | ||
29 | </VHost> | ||
30 | |||
31 | =cut | ||
32 | |||
33 | =head2 register($self, $vhost) | ||
34 | |||
35 | Register the vhost with the module. | ||
36 | |||
37 | =cut | ||
38 | |||
39 | sub register { | ||
40 | my ($self,$vhost) = @_; | ||
41 | my $private_cb = sub { | ||
42 | my ($vh, $cb, $iq) = @_; | ||
43 | unless ($iq->isa("DJabberd::IQ") and defined $iq->to) { | ||
44 | $cb->decline; | ||
45 | return; | ||
46 | } | ||
47 | unless ($iq->to eq $vhost->{server_name}) { | ||
48 | $cb->decline; | ||
49 | return; | ||
50 | } | ||
51 | if ($iq->signature eq 'get-{jabber:iq:time}query') { | ||
52 | $self->_get_time90($vh, $iq); | ||
53 | $cb->stop_chain; | ||
54 | return; | ||
55 | } elsif ($iq->signature eq 'get-{urn:xmpp:time}time') { | ||
56 | $self->_get_time202($vh, $iq); | ||
57 | $cb->stop_chain; | ||
58 | return; | ||
59 | } | ||
60 | $cb->decline; | ||
61 | }; | ||
62 | $vhost->register_hook("switch_incoming_client",$private_cb); | ||
63 | $vhost->register_hook("switch_incoming_server",$private_cb); | ||
64 | $vhost->add_feature("jabber:iq:time"); | ||
65 | $vhost->add_feature("urn:xmpp:time"); | ||
66 | } | ||
67 | |||
68 | sub _get_time90 { | ||
69 | my ($self, $vh, $iq) = @_; | ||
70 | $logger->info('Getting time from : '.$iq->from_jid); | ||
71 | $iq->send_reply('result',qq(<query xmlns="jabber:iq:time">) | ||
72 | .'<utc>'.strftime("%Y%m%dT%H:%M:%S",gmtime).'</utc>' | ||
73 | .'<display>'.gmtime().'</display>' | ||
74 | .'<tz>'.strftime("%Z",gmtime).'</tz>' | ||
75 | .qq(</query>) ); | ||
76 | } | ||
77 | |||
78 | sub _get_time202 { | ||
79 | my ($self, $vh, $iq) = @_; | ||
80 | $logger->info('Getting time from : '.$iq->from_jid); | ||
81 | my $zone = strftime("%z",gmtime); | ||
82 | $zone =~ s/(\d\d)(\d\d)$/$1:$2/; | ||
83 | $iq->send_reply('result',qq(<time xmlns="urn:xmpp:time">) | ||
84 | .'<tzo>'.$zone.'</tzo>' | ||
85 | .'<utc>'.strftime("%Y%m%dT%H:%M:%S",gmtime).'</utc>' | ||
86 | .qq(</time>) ); | ||
87 | } | ||
88 | |||
89 | =head1 AUTHOR | ||
90 | |||
91 | Edward Rudd, C<< <urkle at outoforder.cc> >> | ||
92 | |||
93 | =head1 COPYRIGHT & LICENSE | ||
94 | |||
95 | Copyright 2007 Edward Rudd, all rights reserved. | ||
96 | |||
97 | This program is free software; you can redistribute it and/or modify it | ||
98 | under the same terms as Perl itself. | ||
99 | |||
100 | =cut | ||
101 | |||
102 | 1; # End of DJabberd::Plugin::EntityTime | ||
diff --git a/t/00-load.t b/t/00-load.t new file mode 100644 index 0000000..2ff39a8 --- /dev/null +++ b/t/00-load.t | |||
@@ -0,0 +1,9 @@ | |||
1 | #!perl -T | ||
2 | |||
3 | use Test::More tests => 1; | ||
4 | |||
5 | BEGIN { | ||
6 | use_ok( 'DJabberd::Plugin::EntityTime' ); | ||
7 | } | ||
8 | |||
9 | diag( "Testing DJabberd::Plugin::EntityTime $DJabberd::Plugin::EntityTime::VERSION, Perl $], $^X" ); | ||
diff --git a/t/boilerplate.t b/t/boilerplate.t new file mode 100644 index 0000000..6502722 --- /dev/null +++ b/t/boilerplate.t | |||
@@ -0,0 +1,48 @@ | |||
1 | #!perl -T | ||
2 | |||
3 | use strict; | ||
4 | use warnings; | ||
5 | use Test::More tests => 3; | ||
6 | |||
7 | sub not_in_file_ok { | ||
8 | my ($filename, %regex) = @_; | ||
9 | open my $fh, "<", $filename | ||
10 | or die "couldn't open $filename for reading: $!"; | ||
11 | |||
12 | my %violated; | ||
13 | |||
14 | while (my $line = <$fh>) { | ||
15 | while (my ($desc, $regex) = each %regex) { | ||
16 | if ($line =~ $regex) { | ||
17 | push @{$violated{$desc}||=[]}, $.; | ||
18 | } | ||
19 | } | ||
20 | } | ||
21 | |||
22 | if (%violated) { | ||
23 | fail("$filename contains boilerplate text"); | ||
24 | diag "$_ appears on lines @{$violated{$_}}" for keys %violated; | ||
25 | } else { | ||
26 | pass("$filename contains no boilerplate text"); | ||
27 | } | ||
28 | } | ||
29 | |||
30 | not_in_file_ok(README => | ||
31 | "The README is used..." => qr/The README is used/, | ||
32 | "'version information here'" => qr/to provide version information/, | ||
33 | ); | ||
34 | |||
35 | not_in_file_ok(Changes => | ||
36 | "placeholder date/time" => qr(Date/time) | ||
37 | ); | ||
38 | |||
39 | sub module_boilerplate_ok { | ||
40 | my ($module) = @_; | ||
41 | not_in_file_ok($module => | ||
42 | 'the great new $MODULENAME' => qr/ - The great new /, | ||
43 | 'boilerplate description' => qr/Quick summary of what the module/, | ||
44 | 'stub function definition' => qr/function[12]/, | ||
45 | ); | ||
46 | } | ||
47 | |||
48 | module_boilerplate_ok('lib/DJabberd/Plugin/EntityTime.pm'); | ||
diff --git a/t/pod-coverage.t b/t/pod-coverage.t new file mode 100644 index 0000000..703f91d --- /dev/null +++ b/t/pod-coverage.t | |||
@@ -0,0 +1,6 @@ | |||
1 | #!perl -T | ||
2 | |||
3 | use Test::More; | ||
4 | eval "use Test::Pod::Coverage 1.04"; | ||
5 | plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; | ||
6 | all_pod_coverage_ok(); | ||
@@ -0,0 +1,6 @@ | |||
1 | #!perl -T | ||
2 | |||
3 | use Test::More; | ||
4 | eval "use Test::Pod 1.14"; | ||
5 | plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; | ||
6 | all_pod_files_ok(); | ||