NAME
BusyBird::Main::PSGI::View - view renderer for BusyBird::Main
DESCRIPTION
This is a view renderer object for BusyBird::Main.
This module is rather for internal use. End-users should not use this module directly. Specification in this document may be changed in the future.
CLASS METHODS
$view = BusyBird::Main::PSGI::View->new(%args)
The constructor.
Fields in %args
are:
main_obj
=> BusyBird::Main OBJECT (mandatory)
OBJECT METHODS
$psgi_response = $view->response_notfound([$message])
Returns a simple "404 Not Found" page.
$message
is the message body, which is optional.
Return value $psgi_response
is a PSGI response object.
$psgi_response = $view->response_error_html($http_code, $message)
Returns an HTTP error response in HTML.
$http_code
is HTTP response code, which should be 4** or 5**. $message
is a human-readable error message.
Return value $psgi_response
is a PSGI response object.
$psgi_response = $view->response_json($http_code, $response_object)
Returns a response object whose content is a JSON-fomatted object.
$http_code
is the HTTP response code such as "200", "404" and "500". $response_object
is a reference to an object.
Return value $psgi_response
is a PSGI response object. Its content is $response_object
formatted in JSON.
$response_object
must be encodable by JSON. Otherwise, it returns a PSGI response with HTTP code of 500 (Internal Server Error).
If $http_code
is 200, $response_object
is a hash-ref and $response_object->{error}
does not exist, $response_object->{error}
is automatically set to undef
, indicating the response is successful.
$psgi_response = $view->response_statuses(%args)
Returns a PSGI response object for given status objects.
Fields in %args
are:
statuses
=> ARRAYREF_OF_STATUSES (semi-optional)-
Array-ref of statuses to be rendered. You must set either
statuses
field orerror
field. If not, it croaks. error
=> STR (semi-optional)-
Error string to be rendered. This field must be set when you don't have statuses due to some error.
http_code
=> INT (mandatory)-
HTTP response code.
format
=> STR (mandatory)-
A string specifying rendering format. Possible formats are:
"html"
,"json"
. If unknown format is given, it returns "400 Bad Request" error response. timeline_name
=> STR (optional)-
A string of timeline name for the statuses.
$psgi_response = $view->response_timeline($timeline_name, $script_name)
Returns a PSGI response object of the top view for a timeline.
$timeline_name
is a string of timeline name to be rendered. If the timeline does not exist in $view
's BusyBird::Main object, it returns "404 Not Found" response.
$script_name
is the base path for internal hyperlinks. It should be SCRIPT_NAME
of the PSGI environment.
$psgi_response = $view->response_timeline_list(%args)
Returns a PSGI response object of the view of timeline list.
Fields in %args
are:
script_name
=> STR (mandatory)-
The base path for internal hyperlinks known as
SCRIPT_NAME
. timeline_unacked_counts
=> ARRAYREF (mandatory)-
The data structure keeping the initial unacked counts for timelines. Its structure is like
[ {name => "first timeline name", counts => {total => 0}}, {name => "second timeline name", counts => { total => 10, 0 => 5, 1 => 3 2 => 2 }} ]
total_page_num
=> INT (mandatory)-
Total number of pages for listing all timelines.
cur_page
=> INT (mandatory)-
The current page number of the timeline list. The page number starts with 0.
$functions = $view->template_functions()
Returns a hash-ref of subroutine references for template rendering. They are supposed to be called from Text::Xslate templates.
$functions
contain the following keys. All of their values are subroutine references.
js
=> CODEREF($text)-
Escapes JavaScript value.
link
=> CODEREF($text, %attr)-
Linkifies
$text
with<a>
tag with%attr
attributes.$text
will be HTML-escaped. If$attr{href}
does not look like a valid link URL, it returns the escaped$text
only. image
=> CODEREF(%attr)-
Returns
<img>
tag with%attr
attributes. If$attr{src}
does not look like a valid image URL, it returns an empty string. bb_level
=> CODEREF($level)-
Formats status level.
$level
may beundef
, in which case the level is assumed to be 0.
$functions = $view->template_functions_for_timeline($timeline_name)
Returns a hash-ref of subroutine references for template rendering. They are supposed to be called from Text::Xslate templates.
$timeline_name
is the name of a timeline. $functions
is the set of functions that are dependent on the timeline's configuration.
$functions
contain the following keys. All of their values are subroutine references.
bb_timestamp
=> CODEREF($timestamp_str)-
Returns a timestamp string formatted with the timeline's configuration.
$timestamp_str
is the timestamp in status objects such as$status->{created_at}
. bb_status_permalink
=> CODEREF($status)-
Returns the permalink URL for the status.
bb_text
=> CODEREF($status)-
Returns the HTML text for the status.
AUTHOR
Toshio Ito <toshioito [at] cpan.org>