~fnux/pisk

23113233d8f79eabc23f20cdf5d3077ffcbab571 — Timothée Floure 2 years ago f67ec78
Use switch statement instead of cascade if/elsif
1 files changed, 26 insertions(+), 24 deletions(-)

M disks.pl
M disks.pl => disks.pl +26 -24
@@ 30,7 30,7 @@ Timothée Floure (<timothee.floure@fnux.ch>)
use utf8;
use strict;
use warnings;
use 5.01;
use feature "switch";

use Curses::UI;
use Net::DBus;


@@ 77,31 77,33 @@ sub refresh_listbox_content {
		foreach my $block_device (@{ $drive_tree->{$drive_path} }) {
			my $label = sprintf('  %-15s', get_block_device_path($block_device));

			if (implements_udisks2_interface($block_device, 'Filesystem')) {
				$label .= $block_device->IdType;
			given ($block_device) {
				when (implements_udisks2_interface($_, 'Filesystem')) {
					$label .= $block_device->IdType;

				if (list_filesystem_mountpoints($block_device)) {
					$label .= ' - ' . list_filesystem_mountpoints($block_device);
				}
					if (list_filesystem_mountpoints($block_device)) {
						$label .= ' - ' . list_filesystem_mountpoints($block_device);
					}

				my $filesystem = $block_device->as_interface(
					'org.freedesktop.UDisks2.Filesystem'
				);
				my $humanized_size = $filesystem->Size / (2 ** 30);
				$label .= ' - ' . $humanized_size . ' GB';
			}
			elsif (implements_udisks2_interface($block_device, 'Swapspace')) {
				$label .= 'Swap space';
			}
			elsif (implements_udisks2_interface($block_device, 'Encrypted')) {
				$label .= 'Encrypted';
			}
			elsif (implements_udisks2_interface($block_device, 'Partition')) {
				my $partition = $block_device->as_interface(
					'org.freedesktop.UDisks2.Partition'
				);
				my $humanized_size = $partition->Size / (2 ** 30);
				$label .= ' - ' . $humanized_size . ' GB';
					my $filesystem = $block_device->as_interface(
						'org.freedesktop.UDisks2.Filesystem'
					);
					my $humanized_size = $filesystem->Size / (2 ** 30);
					$label .= ' - ' . $humanized_size . ' GB';
				}
				when (implements_udisks2_interface($_, 'Swapspace')) {
					$label .= 'Swap space';
				}
				when (implements_udisks2_interface($_, 'Encrypted')) {
					$label .= 'Encrypted';
				}
				when (implements_udisks2_interface($_, 'Partition')) {
					my $partition = $block_device->as_interface(
						'org.freedesktop.UDisks2.Partition'
					);
					my $humanized_size = $partition->Size / (2 ** 30);
					$label .= ' - ' . $humanized_size . ' GB';
				}
			}

			push @{ $values }, $block_device;