<?xml version="1.0" encoding="windows-1252"?>
<node id="295475" title="use PerlMonksFacts;" created="2003-09-30 19:49:52" updated="2005-08-10 15:24:39">
<type id="1748">
sourcecode</type>
<author id="114691">
Aristotle</author>
<data>
<field name="doctext">
&lt;code&gt;
package PerlMonksFacts;

=pod

=head1 NAME

PerlMonksFacts - codified knowledge about the automation interfaces of PerlMonks.org

=head1 SYNOPSIS

 use PerlMonksFacts;
 use URI;

 my $uri = URI-&gt;new(pm_url);
 $uri-&gt;query_form(pm_ticker xp =&gt; 'Aristotle');
 print $uri-&gt;as_string, "\n";

=head1 DESCRIPTION

This module abstracts working with the PerlMonks.org automation interfaces.
The main purpose is to put PerlMonks.org ticker URL generation in a blackbox.
As such, the main point of the module is the C&lt;pm_ticker&gt; function.

Since this module is intended to be as abstract as possible, the C&lt;pm_ticker&gt;
and C&lt;pm_url&gt; functions return raw key/value pairs. Their actual use is up to
you; see the L&lt;/"SYNOPSIS"&gt; for an example of building a URI suitable for use
in a HTTP C&lt;GET&gt; request from them.

=head1 INTERFACE

=head2 %pm_nodetype

This hash contains a mapping of PerlMonks.org-internal node type names to human
readable versions. It is mostly cribbed from the code of the live Super Search
page of PerlMonks.org.

=head2 &amp;pm_url

This is simply a constant function that returns "http://www.perlmonks.org".

=head2 &amp;pm_ticker

This function takes the name of a ticker and possibly parameters for it and
returns a list of key/value pairs for URL construction. The following ticker
names are recognized:

=over 4

=item C&lt;nn&gt;, newest nodes xml generator

Takes one parameter - a L&lt;perlfunc/time&gt; style timestamp.

=item C&lt;xp&gt;, XP xml ticker

Optionally takes one parameter - a user name or user homenode ID for whose XP
should be tracked.

=item C&lt;cb&gt;, chatterbox xml ticker

No parameters.

=item C&lt;msg&gt;, private message xml ticker

No parameters.

=item C&lt;users&gt;, other users xml ticker

No parameters.

=item C&lt;query&gt;, node query xml generator

Takes any number of parameters, which should be node IDs for the nodes to query.

=item C&lt;usernodes&gt;, user nodes info xml generator

Takes one parameter: the user whose nodes are to be returned.

=item C&lt;thread&gt;, xml node thread

No parameters.

=back

=head2 &amp;pm_login

This function takes a username and password as parameters and returns a list of
key/value pairs for URL construction.

=head2 &amp;pm_time2unix

This function takes a timestamp in the format used in PerlMonks-generated XML
and returns a L&lt;perlfunc/time&gt; style timestamp.

=head1 BUGS

C&lt;&amp;pm_ticker&gt; does not yet implement the C&lt;types&gt; parameter nor the C&lt;days&gt;
parameter to the newest nodes ticker.

=head1 AUTHOR

Aristotle Pagaltzis L&lt;mailto:pagaltzis@gmx.de&gt;

=head1 LICENSE

This software is in the public domain. It is distributed in the hope that it
will be useful, but B&lt;without any warranty&gt;; without even the implied warranty
of B&lt;merchantability or fitness for a particular purpose&gt;.

=cut

use strict;
use warnings;
no warnings 'once';

use Exporter::Lite;

our @EXPORT = qw(
	%pm_nodetype
	pm_url
	pm_ticker
	pm_login
	pm_time2unix
);

our %pm_nodetype = (
	bookreview             =&gt; 'Book Review',
	bug                    =&gt; '',
	categorized_answer     =&gt; 'Categorized Answer',
	categorized_question   =&gt; 'Categorized Question',
	container              =&gt; '',
	CUFP                   =&gt; 'Cool Uses For Perl',
	data                   =&gt; '',
	dbtable                =&gt; '',
	devtask                =&gt; '',
	document               =&gt; '',
	fullpage               =&gt; '',
	hint                   =&gt; '',
	htmlcode               =&gt; '',
	htmlpage               =&gt; '',
	image                  =&gt; '',
	linktype               =&gt; '',
	mail                   =&gt; '',
	maintenance            =&gt; '',
	modulereview           =&gt; 'Module Review',
	monkdiscuss            =&gt; 'Perl Monks Discussion',
	nodeball               =&gt; '',
	nodegroup              =&gt; '',
	nodeletgroup           =&gt; '',
	nodelet                =&gt; 'Nodelet',
	nodetype               =&gt; '',
	note                   =&gt; 'Note',
	obfuscated             =&gt; 'Obfuscation',
	opcode                 =&gt; '',
	patch                  =&gt; '',
	perlcraft              =&gt; 'Craft',
	perlexercise           =&gt; '',
	perlfunc               =&gt; 'Perl Function',
	perlman                =&gt; 'Perl Manpage',
	perlmeditation         =&gt; 'Meditations',
	perlnews               =&gt; 'News',
	perlquestion           =&gt; 'Seekers of Perl Wisdom',
	perlsolution           =&gt; '',
	perltutorial           =&gt; 'Tutorial',
	pmdevsuperdoc          =&gt; '',
	pmmodule               =&gt; '',
	poem                   =&gt; 'Poem',
	poll                   =&gt; 'Poll',
	quest                  =&gt; 'Quest',
	rawdata                =&gt; '',
	rawpage                =&gt; '',
	request                =&gt; '',
	restricted_superdoc    =&gt; '',
	review                 =&gt; '',
	scratchpad             =&gt; 'Scratch Pad',
	script                 =&gt; '',
	setting                =&gt; '',
	sitedoc                =&gt; '',
	sitefaqlet             =&gt; 'Monk Help',
	snippet                =&gt; 'Snippet',
	sourcecode             =&gt; 'Code',
	sourcecodesection      =&gt; '',
	strangedoc             =&gt; '',
	strangenode            =&gt; '',
	string                 =&gt; '',
	superdoc               =&gt; '',
	superquestionarea      =&gt; '',
	survey                 =&gt; '',
	testquestion           =&gt; '',
	testtype               =&gt; '',
	theme                  =&gt; '',
	themesetting           =&gt; '',
	usergroup              =&gt; '',
	user                   =&gt; 'User',
	wiki                   =&gt; 'Wiki',
	xmlpage                =&gt; '',
);

{
	while(my ($k, $v) = each %pm_nodetype) {
		$v ||= "\u\L$k";
		$v =~ s/(html|xml)/\u$1/i;
	}
}

sub pm_url () { "http://www.perlmonks.org/index.pl" }

{
	my %ticker_node = (
		nn        =&gt;  30175 || "newest nodes xml generator",
		xp        =&gt;  16046 || "XP xml ticker",
		cb        =&gt;  15834 || "chatterbox xml ticker",
		msg       =&gt;  15848 || "private message xml ticker",
		users     =&gt;  15851 || "other users xml ticker",
		query     =&gt;  37150 || "node query xml generator",
		usernodes =&gt;  32704 || "user nodes info xml generator",
		thread    =&gt; 180684 || "xml node thread",
	);

	my %ticker_param = (
		xp        =&gt; sub { @_ ? ( ($_[0] =~ /\D/ ? 'for_user' : 'for_id') =&gt; $_[0] ) : () },
		nn        =&gt; sub { @_ ? ( sinceunixtime =&gt; $_[0] ) : () },
		query     =&gt; sub { nodes =&gt; join(',', @_ ? @_ : '') },
		usernodes =&gt; sub { foruser =&gt; $_[0] },
	);

	sub pm_ticker {
		my $ticker_name = shift;
		my $node = $ticker_node{$ticker_name}
			|| do { require Carp; Carp::croak("Unknown ticker name: $ticker_name") };
		my @param = do {
			$ticker_param{$ticker_name}-&gt;(@_)
				if @_ &amp;&amp; exists $ticker_param{$ticker_name}
		};
		return (node =&gt; $node, @param);
	}
}

sub pm_login {
	my ($user, $pass) = @_;
	return (
		op      =&gt; "login",
		user    =&gt; $user,
		passwd  =&gt; $pass,
		ticker  =&gt; "yes",
	);
}

sub pm_time2unix {
	my ($Y, $M, $D, $h, $m, $s) = unpack "A4 A2 A2 A2 A2 A2", shift;
	$M--;
	require Time::Local;
	Time::Local::timegm($s, $m, $h, $D, $M, $Y);
}
&lt;/code&gt;</field>
<field name="codedescription">
&lt;ul&gt;
	&lt;li&gt;&lt;a href="#name"&gt;NAME&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="#synopsis"&gt;SYNOPSIS&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="#description"&gt;DESCRIPTION&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="#interface"&gt;INTERFACE&lt;/a&gt;&lt;/li&gt;
	&lt;ul&gt;
		&lt;li&gt;&lt;a href="#%pm_nodetype"&gt;%pm_nodetype&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="#&amp;pm_url"&gt;&amp;amp;pm_url&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="#&amp;pm_ticker"&gt;&amp;amp;pm_ticker&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="#&amp;pm_login"&gt;&amp;amp;pm_login&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="#&amp;pm_time2unix"&gt;&amp;amp;pm_time2unix&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
	&lt;li&gt;&lt;a href="#bugs"&gt;BUGS&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="#author"&gt;AUTHOR&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="#license"&gt;LICENSE&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;
&lt;h1&gt;&lt;a name="name"&gt;NAME&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;PerlMonksFacts - codified knowledge about the automation interfaces of PerlMonks.org&lt;/p&gt;
&lt;hr /&gt;
&lt;h1&gt;&lt;a name="synopsis"&gt;SYNOPSIS&lt;/a&gt;&lt;/h1&gt;
&lt;pre&gt;
 use PerlMonksFacts;
 use URI;&lt;/pre&gt;
&lt;pre&gt;
 my $uri = URI-&amp;gt;new(pm_url);
 $uri-&amp;gt;query_form(pm_ticker xp =&amp;gt; 'Aristotle');
 print $uri-&amp;gt;as_string, &amp;quot;\n&amp;quot;;&lt;/pre&gt;
&lt;hr /&gt;
&lt;h1&gt;&lt;a name="description"&gt;DESCRIPTION&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;This module abstracts working with the PerlMonks.org automation interfaces.
The main purpose is to put PerlMonks.org ticker URL generation in a blackbox.
As such, the main point of the module is the &lt;code&gt;pm_ticker&lt;/code&gt; function.&lt;/p&gt;
&lt;p&gt;Since this module is intended to be as abstract as possible, the &lt;code&gt;pm_ticker&lt;/code&gt;
and &lt;code&gt;pm_url&lt;/code&gt; functions return raw key/value pairs. Their actual use is up to
you; see the &lt;a href="#synopsis"&gt;SYNOPSIS&lt;/a&gt; for an example of building a URI suitable for use
in a HTTP &lt;code&gt;GET&lt;/code&gt; request from them.&lt;/p&gt;
&lt;hr /&gt;
&lt;h1&gt;&lt;a name="interface"&gt;INTERFACE&lt;/a&gt;&lt;/h1&gt;
&lt;h2&gt;&lt;a name="%pm_nodetype"&gt;%pm_nodetype&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;This hash contains a mapping of PerlMonks.org-internal node type names to human
readable versions. It is mostly cribbed from the code of the live Super Search
page of PerlMonks.org.&lt;/p&gt;
&lt;/p&gt;
&lt;h2&gt;&lt;a name="&amp;pm_ticker"&gt;&amp;amp;pm_ticker&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;This function takes the name of a ticker and possibly parameters for it and
returns a list of key/value pairs for URL construction. The following ticker
names are recognized:&lt;/p&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;strong&gt;&lt;a name="item_nn%2c_newest_nodes_xml_generator"&gt;&lt;code&gt;nn&lt;/code&gt;, newest nodes xml generator&lt;/a&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;/dt&gt;
&lt;dd&gt;
Takes one parameter - a &lt;em&gt;perlfunc/time&lt;/em&gt; style timestamp.
&lt;/dd&gt;
&lt;dt&gt;&lt;strong&gt;&lt;a name="item_xp%2c_xp_xml_ticker"&gt;&lt;code&gt;xp&lt;/code&gt;, XP xml ticker&lt;/a&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;/dt&gt;
&lt;dd&gt;
Optionally takes one parameter - a user name or user homenode ID for whose XP
should be tracked.
&lt;/dd&gt;
&lt;dt&gt;&lt;strong&gt;&lt;a name="item_cb%2c_chatterbox_xml_ticker"&gt;&lt;code&gt;cb&lt;/code&gt;, chatterbox xml ticker&lt;/a&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;/dt&gt;
&lt;dd&gt;
No parameters.
&lt;/dd&gt;
&lt;dt&gt;&lt;strong&gt;&lt;a name="item_msg%2c_private_message_xml_ticker"&gt;&lt;code&gt;msg&lt;/code&gt;, private message xml ticker&lt;/a&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;/dt&gt;
&lt;dd&gt;
No parameters.
&lt;/dd&gt;
&lt;dt&gt;&lt;strong&gt;&lt;a name="item_users%2c_other_users_xml_ticker"&gt;&lt;code&gt;users&lt;/code&gt;, other users xml ticker&lt;/a&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;/dt&gt;
&lt;dd&gt;
No parameters.
&lt;/dd&gt;
&lt;dt&gt;&lt;strong&gt;&lt;a name="item_query%2c_node_query_xml_generator"&gt;&lt;code&gt;query&lt;/code&gt;, node query xml generator&lt;/a&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;/dt&gt;
&lt;dd&gt;
Takes any number of parameters, which should be node IDs for the nodes to query.
&lt;/dd&gt;
&lt;dt&gt;&lt;strong&gt;&lt;a name="item_usernodes%2c_user_nodes_info_xml_generator"&gt;&lt;code&gt;usernodes&lt;/code&gt;, user nodes info xml generator&lt;/a&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;/dt&gt;
&lt;dd&gt;
Takes one parameter: the user whose nodes are to be returned.
&lt;/dd&gt;
&lt;dt&gt;&lt;strong&gt;&lt;a name="item_thread%2c_xml_node_thread"&gt;&lt;code&gt;thread&lt;/code&gt;, xml node thread&lt;/a&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;/dt&gt;
&lt;dd&gt;
No parameters.
&lt;/dd&gt;
&lt;p&gt;&lt;/p&gt;&lt;/dl&gt;
&lt;h2&gt;&lt;a name="&amp;pm_login"&gt;&amp;amp;pm_login&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;This function takes a username and password as parameters and returns a list of
key/value pairs for URL construction.&lt;/p&gt;
&lt;h2&gt;&lt;a name="&amp;pm_time2unix"&gt;&amp;amp;pm_time2unix&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;This function takes a timestamp in the format used in PerlMonks-generated XML
and returns a &lt;em&gt;perlfunc/time&lt;/em&gt; style timestamp.&lt;/p&gt;
&lt;hr /&gt;
&lt;h1&gt;&lt;a name="bugs"&gt;BUGS&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;&amp;pm_ticker&lt;/code&gt; does not yet implement the &lt;code&gt;types&lt;/code&gt; parameter nor the &lt;code&gt;days&lt;/code&gt;
parameter to the newest nodes ticker.&lt;/p&gt;
&lt;hr /&gt;
&lt;h1&gt;&lt;a name="author"&gt;AUTHOR&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Aristotle Pagaltzis &lt;em&gt;&lt;a href="mailto:pagaltzis@gmx.de"&gt;pagaltzis@gmx.de&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;h1&gt;&lt;a name="license"&gt;LICENSE&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;This software is in the public domain. It is distributed in the hope that it
will be useful, but &lt;strong&gt;without any warranty&lt;/strong&gt;; without even the implied warranty
of &lt;strong&gt;merchantability or fitness for a particular purpose&lt;/strong&gt;.&lt;/p&gt;</field>
<field name="codecategory">
PerlMonks.org Related Scripts</field>
<field name="codeauthor">
/msg [Aristotle]</field>
</data>
</node>
