A. The court or judge to whom the writ is returned shall, immediately after the return thereof, hear and examine the return, and such other matters as may be properly submitted.

B. The petitioner may controvert the return, or object to the sufficiency thereof, or allege any fact to show either that his imprisonment or detention is unlawful or that he is entitled to discharge. The court or judge shall thereupon hear the evidence, and in a summary manner dispose of the party as justice may require.