I thought I would share a bash script since Barton mentioned mucking with the environment.  Thought in the context of this discussion it might not be appreciated.

To use the script just log into Koha on any computer, and use this script on the server to get into perl's debugging mode.  If the script is named Koha_cli.bash, then call it on the server like `bash Koha_cli.bash SESSION_ID_FROM_COOKIE perl -d SCRIPT_TO_DEBUG`

Anyway, here's the script:

#!/bin/bash

# Environment variables to set before running Koha scripts or pages
#  from the command line

export KOHA_CONF=/usr/local/koha3.2/etc/koha-conf.xml
export PERL5LIB=/usr/local/koha3.2/lib

# those two, of course, and

export HTTP_COOKIE="CGISESSID=$1"
export REMOTE_ADDR=205.126.61.239
#export REMOTE_ADDR=127.0.0.1

# These make it look like I'm coming from my laptop
#  after I've logged into Koha from my laptop
# Just have to check the CGISESSID cookie on my laptop, and pass it to this

# Next, run the script
shift  # Drop session id
exec $*


On Wed, Sep 30, 2015 at 10:28 AM, Barton Chittenden <barton@bywatersolutions.com> wrote:


On Wed, Sep 30, 2015 at 10:18 AM, Tomas Cohen Arazi <tomascohen@gmail.com> wrote:

2015-09-30 9:20 GMT-03:00 Philippe Blouin <philippe.blouin@inlibro.com>:
Because the code would be extremely specific to a specific functionality, whereas the code in the libraries is there to be reused.
And let not go overboard with OO.

We embrace the OO paradigm for most of the CRUD operations, but we also have libs containing functions that are used statically, like Koha::Util::MARC, that do specific things and are testable. And is only used in a couple places.
 
A script is a script is a script.  Make it readable, add functions to make it cleaner, make your functions readable.

We have two main kind of scripts: command line scripts, and controller scripts that got too complicated during Koha's life, and we are trying to simplify "as we go".

I think both should be testable.

I would like to make a plea here from a support / trouble-shooting perspective:

The controller scripts are hard to trouble-shoot, because they're CGI -- it's theoretically possible to run the perl debugger across them, but that requires a fair amount of mucking with the environment... If I'm trying to figure out what's happening with some chunk of code, I'd like to write a command line wrapper around a library, and trigger the bits that I want in a controlled manner. I can't do that with any of the code inside the controllers.

Keeping the code in the controllers thin is important not only for test-ability from a unit testing perspective, but also from a trouble-shooting perspective, because they end up being black-boxes that only run inside of Apache.

--Barton

_______________________________________________
Koha-devel mailing list
Koha-devel@lists.koha-community.org
http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/



--
Michael Hafen
Washington County School District Technology Department
Systems Analyst