# Other
{id: other}

## Devel::Cover script
{id: devel-cover-script}

![](examples/test-perl/cover.pl)

## Can module be loaded? use_ok and require_ok
{id: test-use-ok}
{i: use_ok}
{i: require_ok}

{aside}

use_ok and require_ok are not recommended any more. Just **use** or **require** the modules as necessary
and let perl provide the appropriate failure message if either of those fails.
{/aside}
![](examples/test-perl/t/use_ok.t)

```
1..1
ok 1 - use MyTools;
```


## can_ok('Class', qw(method_a method_b));
{id: test-more-can-ok}
{i: can_ok}

can_ok($object, qw(method_a method_b));


{aside}

In order to nicely test if a module has certain methods you can use the can_ok() function of Test::More.
It can be used both on modules and on objects.
{/aside}
![](examples/test-perl/t/can_ok.t)

Output:


```
1..2
ok 1 - MyTools->can('fibonacci')
not ok 2 - MyTools->can('make_tea')
#   Failed test 'MyTools->can('make_tea')'
#   at examples/test-perl/t/can_ok.t line 11.
#     MyTools->can('make_tea') failed
# Looks like you failed 1 test of 2.
```


## All the tests
{id: tests-all-test}

```
Just to show you all the tests of the MyTools module we used
```

![](examples/test-perl/t/all.t)


## Smolder
{id: smolder}
{i: Smolder}

{aside}
Smolder is a web based application to collect and display TAP streams.
It is already available on CPAN. Once installed it can be launched with the smolder
command. By default it provides its own web server and uses SQLite so you don't have
to worry about further configuration. Once you see it and decide that you'd like to use
it in production with many test systems reporting to it then you'll probably invest more
in the installation, use Apache as the front-end server and MySQL as the database but
at the beginning you can use the simple installation.

Once the system is setup you have a web based administrative interface to add projects,
users and associate them with each other. Every user can then upload archived
tap results as generated by the -a flag of prove. The system then provides various views
of the tests results. You can view the details of a single test run and you can already
see some historical data as well.
As of version 1.35 you have to do the following to start the server:

create ~/.smolder and in it create ~/.smolder/smolder.conf with one line:

HostName    smolder.local

In addition you have to change the /etc/hosts file so smolder.local will resolve
to 127.0.0.1 (You can of course use any name with at least one . in it.)

Then you can launch Smolder using the following command:

smolder -c ~/.smolder/smolder.conf

Then you can use your browser to access  it.

The password for the "admin" user is "qa_rocks".
{/aside}


[Smolder](https://metacpan.org/pod/Smolder) by Michael Peters.

`smolder_smoke_signal --server smolder.foo.com:port --username myself --password s3cr3t --file tap.tar.gz --project MyProject`


## Exercise: Smolder
{id: exercise-smolder}

Check if Smolder is already installed and start it.
Add one or more users to it and at least one project and create some associations.
Then run the prove command with the archiving option on the examples/tap files and upload
the resulting file manually using your browser.


Change the test scripts a bit adding more tests. Change tests from success to failure and
from failure to success. After every change run the tests again generating the archive file
and upload it to Smolder. The first few results you should upload manually but later switch
to the use of Smolder smoke signaler.

## Mocking get in LWP::Simple
{id: mocking-get-in-lwp-simple}


![](examples/mock-lwp/t/webapi_mock_lwp_simple.t)

## Read CSV file as array of hashes
{id: read-csv-file-as-array-of-hashes}
{i: csv}

{aside}
The csv function that can be imported from Text::CSV can read a CSV into memory, creating an array of hashes.

Element from the first row will be used as the keys of these hashes and elements from all the other rows will be used as
the values of these hashes.
{/aside}

* [Text::CSV](https://metacpan.org/pod/Text::CSV)

![](examples/other/planets.csv)
![](examples/other/read_csv_as_array_of_hashes.pl)
![](examples/other/read_csv_as_array_of_hashes.out)

## Sort array using sort and sort_by
{id: sort-array-using-sort-and-sort-by}

* [List::UtilsBy](https://metacpan.org/pod/List::UtilsBy)

![](examples/other/sort_by.pl)
![](examples/other/sort_by_complexity.pl)
![](examples/other/sort_by_planets.pl)

## Range iterator
{id: range-iterator}

* [Range::Iter](https://metacpan.org/pod/Range::Iter)

![](examples/other/range.pl)


## Benchmark
{id: benchmark}

* [Benchmark](https://metacpan.org/pod/Benchmark)

![](examples/other/benchmark.pl)

## Bubble sort
{id: bubble-sort}

* [Bubble sort](https://en.wikipedia.org/wiki/Bubble_sort)

![](examples/other/bubble_sort.pl)

## Insert sort
{id: insert-sort}

* [Insert sort](https://en.wikipedia.org/wiki/Insertion_sort)

![](examples/other/insert_sort.pl)


## Merge sort
{id: merge-sort}

* [Merge sort](https://en.wikipedia.org/wiki/Merge_sort)

![](examples/other/merge_sort.pl)

* It can run out of the recursion limit of Perl

## Quicksort
{id: quick-sort}

* [Quciksort](https://en.wikipedia.org/wiki/Quicksort)

![](examples/other/quick_sort.pl)

* The worst-case is if we happen to select the smallest element every time, then the complexity is O(n^2)
* It can run out of the recursion limit of Perl

## Timsort
{id: tim-sort}

* [Timsort](https://en.wikipedia.org/wiki/Timsort)
* Created for Python by Tim Peters

## Traverse directory tree
{id: traverse-directory-tree}

![](examples/other/dirwalk.pl)

## Traverse directory tree with call back
{id: traverse-directory-tree-with-call-back}

![](examples/other/dirwalk_calback.pl)

## Linear search in unorderd array
{id: linear-search-in-unordered-array}

![](examples/other/linear_search.pl)

## Binary search in sorted array
{id: binary-search-in-sorted-array}

![](examples/other/binary_search.pl)

## Convert curl command with -F to LWP::UserAgent
{id: convert-curl-f-to-lwp-useragent}

```
curl -X POST -F field=value -F name=Corion "https://httpbin.org/post" -H  "accept: application/json"
```
![](examples/other/send_f.pl)

## Modify time anomality in two files
{id: modify-time-anomality}

![](examples/other/modify_time_is_the_same.pl)

![](examples/other/modify_time_is_the_same_1.pl)


