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.
This module uses BusyBird::Log for logging.
CLASS METHODS
$view = BusyBird::Main::PSGI::View->new(%args)
The constructor.
Fields in %args are:
main_obj=> BusyBird::Main OBJECT (mandatory)script_name=> STRING (mandatory)-
The URL path to the application root. This must be what you get as
SCRIPT_NAMEin a PSGI environment object.
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
statusesfield orerrorfield. 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","json_only_statuses". 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)
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.
$psgi_response = $view->response_timeline_list(%args)
Returns a PSGI response object of the view of timeline list.
Fields in %args are:
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
$textwith<a>tag with%attrattributes.$textwill be HTML-escaped. If$attr{href}does not look like a valid link URL, it returns the escaped$textonly. image=> CODEREF(%attr)-
Returns
<img>tag with%attrattributes. If$attr{src}does not look like a valid image URL, it returns an empty string. path=> CODEREF($path)-
Returns the appropriate URL path for the given
$path.If
$pathis relative, it returns the$pathunchanged. If$pathis absolute, it prepends theSCRIPT_NAMEto the$path, so that you can use the path in HTML pages. script_name=> CODEREF()-
Returns the
SCRIPT_NAME. bb_level=> CODEREF($level)-
Formats status level.
$levelmay 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_stris 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.
bb_attached_image_urls=> CODEREF($status)-
Returns an array-ref of image URLs attached to the
$status. These images are rendered together with the status text.If
$statusdoesn't have any attached images, it returns an empty array-ref.
AUTHOR
Toshio Ito <toshioito [at] cpan.org>